Ottomata has submitted this change and it was merged. Change subject: Fixes for ganglia types and non standard gmond aggregator ports ......................................................................
Fixes for ganglia types and non standard gmond aggregator ports - Operator comparison type is now inferred from ganglia metric TYPE attribute. - gmetad.conf sources are now properly parsed for non standard gmond ports. RT 6602 Change-Id: I4a8fc1b7d79bbdd21d7a7f67bb84a0ae67e564bb --- M debian/changelog M src/check_ganglios_generic_value M src/ganglia_parser M src/ganglios/ganglios.py 4 files changed, 45 insertions(+), 11 deletions(-) Approvals: Ottomata: Verified; Looks good to me, approved diff --git a/debian/changelog b/debian/changelog index 9b1d073..b61e4f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +ganglios (1.3) precise-wikimedia; urgency=low + + * get_metric_for_host now returns ganglia metric type + * check_ganglios_generic_value now works with types other than float + * ganglios_parser now works with non-standard gmond ports + + -- Andrew Otto (WMF) <o...@wikimedia.org> Wed, 15 Jan 2014 17:10:09 +0000 + ganglios (1.2) stable; urgency=low * changed ganglia_parser to use gmetad.conf instead of nannybot# diff --git a/src/check_ganglios_generic_value b/src/check_ganglios_generic_value index 0326f17..5307ccf 100755 --- a/src/check_ganglios_generic_value +++ b/src/check_ganglios_generic_value @@ -57,15 +57,27 @@ metric = options.metric getmetric = options.getmetric - cur_val_raw = ganglios.get_metric_for_host(host_name, metric) + cur_val_raw, cur_val_type = ganglios.get_metric_for_host(host_name, metric, True) + + # infer the python type we should cast cur_val_raw to based on the + # ganglia metric type + if (cur_val_type in ['float', 'double']): + python_type = float + elif ('int' in cur_val_type): # int32, uint16, uint32, etc. + python_type = int + else: + python_type = str + try: - cur_val = float(cur_val_raw) + # cast cur val to what it should be in python + cur_val = python_type(cur_val_raw) + except TypeError, e: # ganglios didn't return a number - probably None if (cur_val_raw is None): output = "UNKNOWN - check failed, metric not found" else: - output = "UNKNOWN - check failed (returned '%s' when casting '%s')" % (e, cur_val_raw) + output = "UNKNOWN - check failed (returned '%s' when casting '%s'. metric type is %s, attempted to cast to %s)" % (e, cur_val_raw, cur_val_type, python_type) status = 3 sys.stdout.write(output) ganglios.done(status) @@ -79,8 +91,9 @@ # if called with -g, these metrics are optional. Move them here so you don't trigger an exception on casting an empty option op = options.op - warn_value = float(options.warning) - crit_value = float(options.critical) + # cast comparison values to python types for operator comparison + warn_value = python_type(options.warning) + crit_value = python_type(options.critical) if getattr(operator, op)(cur_val, crit_value): status = 2 diff --git a/src/ganglia_parser b/src/ganglia_parser index e9adb90..6f8a165 100755 --- a/src/ganglia_parser +++ b/src/ganglia_parser @@ -127,10 +127,15 @@ logger.info("Retrieving ganglia data from selected hosts...") for host in srcHosts: + port = 8649 + if ':' in host + (host, port) = host.split(':') + port = int(port) + try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(15.0) - s.connect((host, 8649)) + s.connect((host, port)) (fdTF,tmpFile) = tempfile.mkstemp() fdTmpFile = os.fdopen(fdTF, "w+b") while True: diff --git a/src/ganglios/ganglios.py b/src/ganglios/ganglios.py index 75892e4..1be9d2e 100644 --- a/src/ganglios/ganglios.py +++ b/src/ganglios/ganglios.py @@ -102,11 +102,16 @@ sys.stdout.write (bad_host + ' ') return status -def get_metric_for_host(hostname, metricname): +def get_metric_for_host(hostname, metricname, return_type=False): """ using the new-style (one file per host), this - takes a hostname, looks up the metric, and returns its value - This is method (b) above + takes a hostname, looks up the metric, and returns its value and type + This is method (b) above. + + If you would like to have the ganglia metric TYPE returned to you as well, + set return_type to True. In this case, a (value, type) tuple will be + returned. The second value in the tuple will be a python string + describing the ganglia metric type. """ # first, find the canonical name for the host passed in @@ -154,12 +159,15 @@ for metric in tree.findall('METRIC'): # found a metric we care about. if metric.attrib['NAME'] == metricname: - return metric.attrib['VAL'] + if return_type: + return (metric.attrib['VAL'], metric.attrib['TYPE']) + else: + return metric.attrib['VAL'] + except expat.ExpatError: sys.stdout.write("XML parse error") done(2) f_hndl.close() - def done (status): -- To view, visit https://gerrit.wikimedia.org/r/107501 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4a8fc1b7d79bbdd21d7a7f67bb84a0ae67e564bb Gerrit-PatchSet: 3 Gerrit-Project: operations/software/ganglios Gerrit-Branch: master Gerrit-Owner: Ottomata <o...@wikimedia.org> Gerrit-Reviewer: Milimetric <dandree...@wikimedia.org> Gerrit-Reviewer: Ottomata <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits