Fix plugins for hostname-free metrics
When porting StackLight to MK, we missed an important code change [1]
that fixes the metrics not associated to a particular host. This change
is backporting the fix in the current code base.
[1] https://review.openstack.org/#/c/378689/
Change-Id: I177db6f68e23ac4fc7feb45df1f30be1fe124acc
diff --git a/collectd/files/plugin/collectd_base.py b/collectd/files/plugin/collectd_base.py
index 4e6eaff..e869a97 100644
--- a/collectd/files/plugin/collectd_base.py
+++ b/collectd/files/plugin/collectd_base.py
@@ -48,7 +48,7 @@
MAX_IDENTIFIER_LENGTH = 63
- def __init__(self, collectd, service_name=None):
+ def __init__(self, collectd, service_name=None, local_check=True):
self.debug = False
self.timeout = 5
self.max_retries = 3
@@ -61,6 +61,7 @@
self.do_collect_data = True
self.service_name = service_name
+ self.local_check = local_check
def config_callback(self, conf):
for node in conf.children:
@@ -95,7 +96,8 @@
def dispatch_check_metric(self, check, failure=None):
metric = {
- 'meta': {'service_check': self.service_name or self.plugin},
+ 'meta': {'service_check': self.service_name or self.plugin,
+ 'local_check': self.local_check},
'values': check,
}
diff --git a/collectd/files/plugin/collectd_elasticsearch_cluster.py b/collectd/files/plugin/collectd_elasticsearch_cluster.py
index 64b97d1..5db5a67 100644
--- a/collectd/files/plugin/collectd_elasticsearch_cluster.py
+++ b/collectd/files/plugin/collectd_elasticsearch_cluster.py
@@ -39,7 +39,8 @@
yield {
'type_instance': 'health',
- 'values': HEALTH_MAP[data['status']]
+ 'values': HEALTH_MAP[data['status']],
+ 'meta': {'discard_hostname': True}
}
for metric in METRICS:
@@ -51,10 +52,11 @@
continue
yield {
'type_instance': metric,
- 'values': value
+ 'values': value,
+ 'meta': {'discard_hostname': True}
}
-plugin = ElasticsearchClusterHealthPlugin(collectd)
+plugin = ElasticsearchClusterHealthPlugin(collectd, local_check=False)
def config_callback(conf):
diff --git a/collectd/files/plugin/collectd_pacemaker.py b/collectd/files/plugin/collectd_pacemaker.py
index 87dc470..dd78a9f 100644
--- a/collectd/files/plugin/collectd_pacemaker.py
+++ b/collectd/files/plugin/collectd_pacemaker.py
@@ -101,7 +101,8 @@
yield {
'type_instance': 'local_resource_active',
'values': same_hostname(node),
- 'meta': {'resource': self.notify_resource}
+ 'meta': {'resource': self.notify_resource,
+ 'host': shorten_hostname(self.hostname)}
}
summary = root.find('summary')
@@ -111,6 +112,7 @@
yield {
'type_instance': 'local_dc_active',
'values': same_hostname(current_dc),
+ 'meta': {'host': shorten_hostname(self.hostname)}
}
if current_dc.get('name') != self.hostname:
@@ -244,7 +246,12 @@
# value because crm_mon doesn't provide the exact number. To estimate
# the number of operations applied to a resource, the plugin keeps a
# copy of call_ids and compares it with the current value.
- for node in root.find('node_history').iter('node'):
+
+ history = root.find('node_history')
+ if history is None:
+ return
+
+ for node in history.iter('node'):
hostname = shorten_hostname(node.get('name'))
if hostname not in self.history:
self.history[hostname] = {}
@@ -283,7 +290,7 @@
}
-plugin = CrmMonitorPlugin(collectd)
+plugin = CrmMonitorPlugin(collectd, local_check=False)
def init_callback():