Skip to content

Commit 563415e

Browse files
authored
Merge pull request #8 from skob/master
add ability to change uris
2 parents 0f63a83 + 97356f7 commit 563415e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

collectd_prometheus.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
DEFAULT_INTERVAL = 30
2727
DEFAULT_TIMEOUT = 30
2828
DEFAULT_PROTOCOL = 'http'
29+
DEFAULT_URI = '/metrics'
2930
DEFAULT_HOST = '127.0.0.1'
3031
DEFAULT_PORT = '8080'
3132
DEFAULT_PROCESS = 'unknown'
@@ -36,6 +37,7 @@
3637
KEY_INTERVAL = 'Interval'
3738
KEY_PORT = 'Port'
3839
KEY_HOST = 'Host'
40+
KEY_URI = 'Uri'
3941
KEY_REGEX_FILTER = 'Filter'
4042
KEY_TIMEOUT = 'Timeout'
4143
KEY_SSL_IGNORE = 'SslIgnore'
@@ -51,6 +53,7 @@ def __init__(self):
5153
self.process = DEFAULT_PROCESS
5254
self.host = DEFAULT_HOST
5355
self.port = DEFAULT_PORT
56+
self.uri = DEFAULT_URI
5457
self.protocol = DEFAULT_PROTOCOL
5558
self.timeout = DEFAULT_TIMEOUT
5659
self.regex_filters = []
@@ -67,6 +70,8 @@ def config(self, cfg):
6770
self.host = children.values[0]
6871
if children.key == KEY_PORT:
6972
self.port = children.values[0]
73+
if children.key == KEY_URI:
74+
self.uri = children.values[0]
7075
if children.key == KEY_PROTOCOL:
7176
self.protocol = children.values[0]
7277
if children.key == KEY_TIMEOUT:
@@ -119,7 +124,7 @@ def read(self):
119124
kwargs.update({'timeout': process.timeout})
120125

121126
try:
122-
metrics = requests.get("%s://%s:%s/metrics" % (process.protocol, process.host, process.port), **kwargs).content
127+
metrics = requests.get("%s://%s:%s%s" % (process.protocol, process.host, process.port, process.uri), **kwargs).content.decode()
123128
for family in text_string_to_metric_families(metrics):
124129
for sample in family.samples:
125130
# Normalize metric name
@@ -146,7 +151,7 @@ def read(self):
146151
else:
147152
collectd.debug("Name: {0} not match Labels: {1} Value: {2}".format(*sample))
148153
except Exception as e:
149-
collectd.error('unable to get prometheus data %s://%s:%s/metrics with current configuration %s: %s' % (process.protocol, process.host, process.port, json.dumps(process.__dict__), e))
154+
collectd.error('unable to get prometheus data %s://%s:%s%s with current configuration %s: %s' % (process.protocol, process.host, process.port, process.uri, json.dumps(process.__dict__), e))
150155

151156
def init():
152157
signal.signal(signal.SIGCHLD, signal.SIG_DFL)

0 commit comments

Comments
 (0)