Files
scylladb/tools/scyllatop/prometheus.py
Amnon Heiman bc7503feee Scyllatop to use prometheus by default
Scylla now expose the prometheus API by default. This patch chagnes
scyllatop to use the Prometheus API, the collect API is still available.

The main changes in the patch:
* Move collectd specific logic inside collectd.
* Add support for help information.
* Add command line to configure prometheus end point and to enable
collectd.

* Add a prometheus class that collect information from prometheus.

Fixes: #1541
Message-Id: <20180531124156.26336-1-amnon@scylladb.com>
2018-05-31 18:00:22 +03:00

26 lines
807 B
Python
Executable File

#! /usr/bin/python
import sys
import urllib2
import re
class Prometheus(object):
_FIRST_LINE_PATTERN = re.compile('^(?P<lines>\d+)')
_METRIC_INFO_PATTERN = re.compile('^(?P<key>.+) (?P<value>[^ ]+)[ ]*$')
_METRIC_DISCOVER_PATTERN = re.compile('^(?P<metric>[^#].+) (?P<value>[^ ]+)[ ]*$')
_METRIC_DISCOVER_PATTERN_WITH_HELP = re.compile('^# HELP (?P<metric>[^ ]+)(?P<help>.*)$')
def __init__(self, host):
self._host = host
def read_metrics(self):
return urllib2.urlopen(self._host).readlines()
def get_metrics(self):
return self.read_metrics()
def query_val(self, val):
return [l for l in self.get_metrics() if (not l.startswith('#')) and (val=="" or re.match(val, l))]
def query_list(self):
return self.get_metrics()