From e5416168ad921b0c5eded0e67ca21ea0a0527566 Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Fri, 12 Feb 2016 15:23:11 +0100 Subject: [PATCH 1/6] IPMI: use local ipmitool --- ipmi/conf.d/ipmi.pyconf | 22 ---------------------- ipmi/python_modules/ipmi.py | 8 +------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/ipmi/conf.d/ipmi.pyconf b/ipmi/conf.d/ipmi.pyconf index 600c5f07..d788b284 100644 --- a/ipmi/conf.d/ipmi.pyconf +++ b/ipmi/conf.d/ipmi.pyconf @@ -7,28 +7,6 @@ modules { param metric_prefix { value = "ipmi" } - - # IP of rhe IPMI - param ipmi_ip { - value = "10.1.2.3" - } - - param username { - value = "admin" - } - - param password { - value = "secret" - } - - param level { - value = "USER" - } - - # Location of timeout binary - param timeout_bin { - value = "/usr/bin/timeout" - } # Location of ipmitool binary param timeout_bin { diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 24769c11..029b0a0d 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -24,13 +24,7 @@ def get_metrics(params): new_metrics = {} units = {} - command = [ params['timeout_bin'], - "3", params['ipmitool_bin'], - "-H", params['ipmi_ip'], - "-U", params['username'], - '-P', params['password'], - '-L', params['level'], - 'sensor'] + command = [params['ipmitool_bin'], 'sdr'] p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0][:-1] From c65ff6579fedc1de72f239f04f97cdeabb248290 Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Fri, 12 Feb 2016 15:26:05 +0100 Subject: [PATCH 2/6] IPMI: fix get_metrics call. Now the module works again --- ipmi/python_modules/ipmi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 029b0a0d..d513b44d 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -14,7 +14,7 @@ stats_pos = {} -def get_metrics(params): +def get_metrics(): """Return all metrics""" global METRICS @@ -24,7 +24,7 @@ def get_metrics(params): new_metrics = {} units = {} - command = [params['ipmitool_bin'], 'sdr'] + command = ['ipmitool', 'sdr'] p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0][:-1] @@ -101,7 +101,7 @@ def metric_init(params): 'groups' : 'XXX', } - metrics = get_metrics(params)[0] + metrics = get_metrics()[0] for item in metrics['data']: descriptors.append(create_desc(Desc_Skel, { From 658096e689d3692b5c62a6e8c3d6869b85efe773 Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Fri, 12 Feb 2016 15:26:41 +0100 Subject: [PATCH 3/6] IPMI: fix ipmitool parser --- ipmi/python_modules/ipmi.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index d513b44d..20f51e50 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -33,7 +33,9 @@ def get_metrics(): data = v.split("|") try: metric_name = data[0].strip().lower().replace("+", "").replace(" ", "_") - value = data[1].strip() + data[1] = data[1].strip().split(" ") + value = data[1][0].strip() + unit = " ".join(data[1][1:]) # Skip missing sensors if re.search("(0x)", value ) or value == 'na': @@ -46,8 +48,8 @@ def get_metrics(): metric_value = float(vmatch.group(1)) new_metrics[metric_name] = metric_value - units[metric_name] = data[2].strip().replace("degrees C", "C") - + units[metric_name] = unit.replace("degrees C", "C") + except ValueError: continue except IndexError: From 31b4fbb36c0d3f2b39dfe65c29e6ae2e76dec378 Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Fri, 12 Feb 2016 15:27:55 +0100 Subject: [PATCH 4/6] IPMI: fix metrics name substitution. strip('ipmi_') would replace all i, p, m, and underscores instead of the "ipmi_" sting --- ipmi/python_modules/ipmi.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 20f51e50..bac3bbd2 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -67,18 +67,11 @@ def get_metrics(): def get_value(name): """Return a value for the requested metric""" - try: - - metrics = get_metrics()[0] - - name = name.lstrip('ipmi_') - - result = metrics['data'][name] + metrics = get_metrics()[0] - except Exception: - result = 0 + name = re.sub('ipmi_', '', name) - return result + return metrics['data'][name] def create_desc(skel, prop): d = skel.copy() From e28c7c3964d6d248b345985affffc183ae515312 Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Fri, 12 Feb 2016 15:29:58 +0100 Subject: [PATCH 5/6] IPMI: run autopep8. no logic changes --- ipmi/python_modules/ipmi.py | 80 +++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index bac3bbd2..ee4774bc 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -6,13 +6,14 @@ import subprocess METRICS = { - 'time' : 0, - 'data' : {} + 'time': 0, + 'data': {} } METRICS_CACHE_MAX = 5 -stats_pos = {} +stats_pos = {} + def get_metrics(): """Return all metrics""" @@ -21,10 +22,10 @@ def get_metrics(): if (time.time() - METRICS['time']) > METRICS_CACHE_MAX: - new_metrics = {} - units = {} + new_metrics = {} + units = {} - command = ['ipmitool', 'sdr'] + command = ['ipmitool', 'sdr'] p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0][:-1] @@ -32,13 +33,14 @@ def get_metrics(): for i, v in enumerate(p.split("\n")): data = v.split("|") try: - metric_name = data[0].strip().lower().replace("+", "").replace(" ", "_") + metric_name = data[0].strip().lower().replace( + "+", "").replace(" ", "_") data[1] = data[1].strip().split(" ") value = data[1][0].strip() unit = " ".join(data[1][1:]) # Skip missing sensors - if re.search("(0x)", value ) or value == 'na': + if re.search("(0x)", value) or value == 'na': continue # Extract out a float value @@ -54,8 +56,8 @@ def get_metrics(): continue except IndexError: continue - - METRICS = { + + METRICS = { 'time': time.time(), 'data': new_metrics, 'units': units @@ -73,57 +75,59 @@ def get_value(name): return metrics['data'][name] + def create_desc(skel, prop): d = skel.copy() - for k,v in prop.iteritems(): + for k, v in prop.iteritems(): d[k] = v return d + def metric_init(params): global descriptors, metric_map, Desc_Skel descriptors = [] Desc_Skel = { - 'name' : 'XXX', - 'call_back' : get_value, - 'time_max' : 60, - 'value_type' : 'float', - 'format' : '%.5f', - 'units' : 'count/s', - 'slope' : 'both', # zero|positive|negative|both - 'description' : 'XXX', - 'groups' : 'XXX', - } + 'name': 'XXX', + 'call_back': get_value, + 'time_max': 60, + 'value_type': 'float', + 'format': '%.5f', + 'units': 'count/s', + 'slope': 'both', # zero|positive|negative|both + 'description': 'XXX', + 'groups': 'XXX', + } metrics = get_metrics()[0] - - for item in metrics['data']: - descriptors.append(create_desc(Desc_Skel, { - "name" : params['metric_prefix'] + "_" + item, - 'groups' : params['metric_prefix'], - 'units' : metrics['units'][item] - })) + for item in metrics['data']: + descriptors.append(create_desc(Desc_Skel, { + "name" : params['metric_prefix'] + "_" + item, + 'groups' : params['metric_prefix'], + 'units' : metrics['units'][item] + })) return descriptors + def metric_cleanup(): '''Clean up the metric module.''' pass -#This code is for debugging and unit testing +# This code is for debugging and unit testing if __name__ == '__main__': - + params = { - "metric_prefix" : "ipmi", - "ipmi_ip" : "10.1.2.3", - "username" : "ADMIN", - "password" : "secret", - "level" : "USER", - "ipmitool_bin" : "/usr/bin/ipmitool", - "timeout_bin" : "/usr/bin/timeout" - } + "metric_prefix": "ipmi", + "ipmi_ip": "10.1.2.3", + "username": "ADMIN", + "password": "secret", + "level": "USER", + "ipmitool_bin": "/usr/bin/ipmitool", + "timeout_bin": "/usr/bin/timeout" + } descriptors = metric_init(params) while True: From 7a6bf7c51606509c8e6654bf0228f23371fdcd4f Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Fri, 12 Feb 2016 15:36:48 +0100 Subject: [PATCH 6/6] IPMI: updated doc and config. The module now expects ipmitool to be in the $PATH env variable --- ipmi/README.mkdn | 7 +------ ipmi/conf.d/ipmi.pyconf | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/ipmi/README.mkdn b/ipmi/README.mkdn index f5c1f0ea..c123319b 100644 --- a/ipmi/README.mkdn +++ b/ipmi/README.mkdn @@ -35,9 +35,6 @@ This module allows you to collect system statistics from IPMI e.g. Install =============== -It requires installation of the timeout binary e.g. - - apt-get install timeout Copy ipmi.py from python_modules to your python modules directory e.g. @@ -47,9 +44,7 @@ and ipmi.pyconf to /etc/ganglia/conf.d/ -In ipmi.pyconf adjust IPMI interface IP, username and password. - -Restart Gmond and you are done. +Adjust ipmi.pyconf, restart Gmond and you are done. ## AUTHOR diff --git a/ipmi/conf.d/ipmi.pyconf b/ipmi/conf.d/ipmi.pyconf index d788b284..aa8ec014 100644 --- a/ipmi/conf.d/ipmi.pyconf +++ b/ipmi/conf.d/ipmi.pyconf @@ -8,11 +8,6 @@ modules { value = "ipmi" } - # Location of ipmitool binary - param timeout_bin { - value = "/usr/bin/ipmitool" - } - } }