Files
scylladb/tools/scyllatop/prometheus.py
Avi Kivity 8e9989685d scyllatop: complete conversion to python3
d2dbbba139 converted scyllatop's interperter to Python 3, but neglected to do
the actual conversion. This patch does so, by running 2to3 over allfiles and adding
an additional bytes->string decode step in prometheus.py. Superfluous 2to3 changes
to print() calls were removed.
Message-Id: <20190117124121.7409-1-avi@scylladb.com>
2019-01-17 12:50:25 +00:00

25 lines
838 B
Python
Executable File

import urllib.request, urllib.error, urllib.parse
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 urllib.request.urlopen(self._host).read().decode('utf-8').splitlines()
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()