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 600c5f07..aa8ec014 100644 --- a/ipmi/conf.d/ipmi.pyconf +++ b/ipmi/conf.d/ipmi.pyconf @@ -7,33 +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 { - value = "/usr/bin/ipmitool" - } } diff --git a/ipmi/python_modules/ipmi.py b/ipmi/python_modules/ipmi.py index 24769c11..ee4774bc 100644 --- a/ipmi/python_modules/ipmi.py +++ b/ipmi/python_modules/ipmi.py @@ -6,31 +6,26 @@ import subprocess METRICS = { - 'time' : 0, - 'data' : {} + 'time': 0, + 'data': {} } METRICS_CACHE_MAX = 5 -stats_pos = {} +stats_pos = {} -def get_metrics(params): + +def get_metrics(): """Return all metrics""" global METRICS if (time.time() - METRICS['time']) > METRICS_CACHE_MAX: - new_metrics = {} - units = {} + 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 = ['ipmitool', 'sdr'] p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0][:-1] @@ -38,11 +33,14 @@ def get_metrics(params): for i, v in enumerate(p.split("\n")): data = v.split("|") try: - metric_name = data[0].strip().lower().replace("+", "").replace(" ", "_") - value = data[1].strip() + 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 @@ -52,14 +50,14 @@ def get_metrics(params): 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: continue - - METRICS = { + + METRICS = { 'time': time.time(), 'data': new_metrics, 'units': units @@ -71,70 +69,65 @@ def get_metrics(params): def get_value(name): """Return a value for the requested metric""" - try: - - metrics = get_metrics()[0] - - name = name.lstrip('ipmi_') + metrics = get_metrics()[0] - result = metrics['data'][name] + name = re.sub('ipmi_', '', name) - except Exception: - result = 0 + return metrics['data'][name] - return result 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] - metrics = get_metrics(params)[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] - })) - + 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: