Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ipmi module #216

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ipmi/README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
27 changes: 0 additions & 27 deletions ipmi/conf.d/ipmi.pyconf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

}

Expand Down
109 changes: 51 additions & 58 deletions ipmi/python_modules/ipmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,41 @@
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]

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
Expand All @@ -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
Expand All @@ -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:
Expand Down