Allow to set the metric name per URL for http_check plugin
Change-Id: I521055718afacdea81ae898e398ec5d2c5f5fd23
diff --git a/collectd/files/collectd_http_check.conf b/collectd/files/collectd_http_check.conf
index c9e418e..d2ff29e 100644
--- a/collectd/files/collectd_http_check.conf
+++ b/collectd/files/collectd_http_check.conf
@@ -11,6 +11,9 @@
{%- if params.get('expected_content') %}
ExpectedContent "{{ name }}" "{{ params.expected_content|replace('"','\\"') }}"
{%- endif %}
+ {%- if params.get('metric_name') %}
+ MetricName "{{ name }}" "{{ params.metric_name }}"
+ {%- endif %}
{%- if params.verify is defined %}
Verify "{{ name }}" "{{ params.verify }}"
{%- endif %}
diff --git a/collectd/files/plugin/collectd_base.py b/collectd/files/plugin/collectd_base.py
index 6643693..36c0060 100644
--- a/collectd/files/plugin/collectd_base.py
+++ b/collectd/files/plugin/collectd_base.py
@@ -122,9 +122,10 @@
"""Iterate over the collected metrics
This class must be implemented by the subclass and should yield dict
- objects that represent the collected values. Each dict has 6 keys:
+ objects that represent the collected values. Each dict has 7 keys:
- 'values', a scalar number or a list of numbers if the type
defines several datasources.
+ - 'plugin' (optional)
- 'type_instance' (optional)
- 'plugin_instance' (optional)
- 'type' (optional, default='gauge')
@@ -153,9 +154,9 @@
(self.plugin, type_instance[:24], len(type_instance),
self.MAX_IDENTIFIER_LENGTH))
- plugin_instance = metric.get('plugin_instance', self.plugin_instance)
+ plugin_instance = metric.get('plugin_instance') or self.plugin_instance
v = self.collectd.Values(
- plugin=self.plugin,
+ plugin=metric.get('plugin') or self.plugin,
host=metric.get('hostname', ''),
type=metric.get('type', 'gauge'),
plugin_instance=plugin_instance,
diff --git a/collectd/files/plugin/collectd_http_check.py b/collectd/files/plugin/collectd_http_check.py
index 1ad78c5..e909eb4 100644
--- a/collectd/files/plugin/collectd_http_check.py
+++ b/collectd/files/plugin/collectd_http_check.py
@@ -38,6 +38,7 @@
self.timeout = 3
self.max_retries = 2
+ self.metric_names = {}
self.interval = base.INTERVAL
self.polling_interval = base.INTERVAL
@@ -57,6 +58,8 @@
for node in config.children:
if node.key == "Url":
self.urls[node.values[0]] = node.values[1]
+ elif node.key == 'MetricName':
+ self.metric_names[node.values[0]] = node.values[1]
elif node.key == 'ExpectedCode':
self.expected_codes[node.values[0]] = int(node.values[1])
elif node.key == 'ExpectedContent':
@@ -146,7 +149,10 @@
for name, url in self.urls.items():
r = self.check_url(name, url)
if r:
- yield {'type_instance': name, 'values': r}
+ yield {'meta': {'service': name},
+ 'values': r,
+ 'plugin': self.metric_names.get(name),
+ }
plugin = HTTPCheckPlugin(collectd, disable_check_metric=True)