@cryptotaxi247 / netdata-1 / commits / 0c70fe4d7

partial rewrite of _get_data()

Evgeniy Kostenko committed Aug 3, 2018 at 06:41 UTC 0c70fe4d79cff7fb1598f43da28e9d677beea67c
1 file changed +36 -32
python.d/monit.chart.py
+36 -32
@@ -3,6 +3,7 @@
3 # Author: Evgeniy K. (n0guest)
4 # SPDX-License-Identifier: GPL-3.0+
5
6 +import copy
7 import xml.etree.ElementTree as ET
8 from bases.FrameworkServices.UrlService import UrlService
9
@@ -104,43 +105,46 @@ class Service(UrlService):
105 return None
106
107 data = {}
107 - for svc_id in DEFAULT_SERVICES_IDS:
108 - svc_category = MONIT_SERVICE_NAMES[svc_id].lower()
109 - if svc_category == 'system':
108 + for service_id in DEFAULT_SERVICES_IDS:
109 + service_category = MONIT_SERVICE_NAMES[service_id].lower()
110 + if service_category == 'system':
111 self.debug("Skipping service from 'System' category, because it's useless in graphs")
112 continue
113
113 - xpath_query = "./service[@type='%d']" % (svc_id)
114 - self.debug("Searching for %s as %s" % (svc_category, xpath_query))
115 - for svc in xml.findall(xpath_query):
116 - svc_name = svc.find('name').text
117 - svc_status = svc.find('status').text
118 - svc_monitor = svc.find('monitor').text
119 - self.debug('=> found %s with type=%s, status=%s, monitoring=%s' % (svc_name, svc_id, svc_status, svc_monitor))
114 + xpath_query = "./service[@type='%d']" % (service_id)
115 + self.debug("Searching for %s as %s" % (service_category, xpath_query))
116 + for service_node in xml.findall(xpath_query):
117
121 - dimension_key = svc_category + '_' + svc_name
122 - if dimension_key not in self.charts[svc_category]:
123 - self.charts[svc_category].add_dimension([dimension_key, svc_name, 'absolute'])
124 - data[dimension_key] = 1 if svc_status == "0" and svc_monitor == "1" else 0
118 + service_name = service_node.find('name').text
119 + service_status = service_node.find('status').text
120 + service_monitoring = service_node.find('monitor').text
121 + self.debug('=> found %s with type=%s, status=%s, monitoring=%s' % (service_name, service_id, service_status, service_monitoring))
122
126 - if svc_category == 'process':
127 - for node in ('uptime', 'threads', 'children'):
128 - node_value = svc.find(node)
129 - if node_value != None:
130 - if node == 'uptime' and int(node_value.text) < 0:
131 - self.debug('Skipping bugged metrics with negative uptime')
132 - continue
133 - dimension_key = 'process_%s_%s' % (node, svc_name)
134 - if dimension_key not in self.charts['process_' + node]:
135 - self.charts['process_' + node].add_dimension([dimension_key, svc_name, 'absolute'])
136 - data[dimension_key] = int(node_value.text)
123 + dimension_key = service_category + '_' + service_name
124 + if dimension_key not in self.charts[service_category]:
125 + self.charts[service_category].add_dimension([dimension_key, service_name, 'absolute'])
126 + data[dimension_key] = 1 if service_status == "0" and service_monitoring == "1" else 0
127
138 - if svc_category == 'host':
139 - node_value = svc.find('./icmp/responsetime')
140 - if node_value != None:
141 - dimension_key = 'host_latency_%s' % (svc_name)
142 - if dimension_key not in self.charts['host_latency']:
143 - self.charts['host_latency'].add_dimension([dimension_key, svc_name, 'absolute', 1000, 1000000])
144 - data[dimension_key] = float(node_value.text) * 1000000
128 + if service_category == 'process':
129 + for subnode in ('uptime', 'threads', 'children'):
130 + subnode_value = service_node.find(subnode)
131 + if subnode_value == None:
132 + continue
133 + if subnode == 'uptime' and int(subnode_value.text) < 0:
134 + self.debug('Skipping bugged metrics with negative uptime (monit before v5.16')
135 + continue
136 + dimension_key = 'process_%s_%s' % (subnode, service_name)
137 + if dimension_key not in self.charts['process_' + subnode]:
138 + self.charts['process_' + subnode].add_dimension([dimension_key, service_name, 'absolute'])
139 + data[dimension_key] = int(subnode_value.text)
140 +
141 + if service_category == 'host':
142 + subnode_value = service_node.find('./icmp/responsetime')
143 + if subnode_value == None:
144 + continue
145 + dimension_key = 'host_latency_%s' % (service_name)
146 + if dimension_key not in self.charts['host_latency']:
147 + self.charts['host_latency'].add_dimension([dimension_key, service_name, 'absolute', 1000, 1000000])
148 + data[dimension_key] = float(subnode_value.text) * 1000000
149
150 return data or None