Last active
October 18, 2023 08:45
-
-
Save totallyunknown/61a673050cb7fc0cd547 to your computer and use it in GitHub Desktop.
Prometheus Exporter for IPMI Sensor Status and Power usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Tested with SuperMicro | |
import re, subprocess, pprint, time, os, sys | |
if not os.path.exists("/usr/sbin/ipmi-sensors"): | |
print >> sys.stderr, 'freeipmi tools are not installed' | |
sys.exit() | |
p = subprocess.Popen(['/usr/sbin/ipmi-sensors', '--ipmimonitoring-legacy-output', '--ignore-not-available-sensors'], stdout=subprocess.PIPE) | |
lines, err = p.communicate() | |
epoch = int(time.time() * 1000) | |
show_help = {} | |
for line in lines.splitlines(): | |
id, sensor, unit_l, unit, value = re.split('\s\|\s',line) | |
if unit_l == 'Temperature': | |
if unit_l not in show_help: | |
print "# HELP ipmi_temperature Sensor temperatures in Degree Celsius" | |
print "# TYPE ipmi_temperature gauge" | |
show_help[unit_l]=1 | |
sensor = sensor.replace(" Temp","") | |
print 'ipmi_{0}{{sensor="{1}"}} {2}'.format(unit_l.lower(), sensor, float(value)) | |
if unit_l == 'Voltage': | |
if unit_l not in show_help: | |
print "# HELP ipmi_power_voltage IPMI Voltage" | |
print "# TYPE ipmi_power_voltage gauge" | |
show_help[unit_l]=1 | |
print 'ipmi_{0}{{sensor="{1}"}} {2}'.format(unit_l.lower(), sensor, float(value)) | |
if unit_l == 'Power Supply': | |
if unit_l not in show_help: | |
print "# HELP ipmi_power_supply_status FRU Status" | |
print "# TYPE ipmi_power_supply_status gauge" | |
show_help[unit_l]=1 | |
sensor = sensor.replace(" Status","") | |
if value == "\'Presence detected\'": | |
value = "1" | |
else: | |
value = "0" | |
print 'ipmi_power_supply_status{{fru="{0}"}} {1}'.format(sensor, int(value)) | |
if unit_l == 'Physical Security': | |
print "# HELP ipmi_chassis_intrusion Chassis Intrusion Sensor Status" | |
print "# TYPE ipmi_chassis_intrusion gauge" | |
if value == "\'OK\'": | |
value = "0" | |
else: | |
value = "1" | |
print "ipmi_chassis_intrusion " + value | |
p = subprocess.Popen(['/usr/sbin/ipmi-oem', 'intelnm', 'get-node-manager-statistics'], stdout=subprocess.PIPE) | |
lines, err = p.communicate() | |
print "# HELP ipmi_power_usage_watts Power usage in Watts" | |
print "# TYPE ipmi_power_usage_watts GAUGE" | |
#pattern = re.compile("^[Average|Maximum|Minimum|Current].+Power") | |
pattern = re.compile("^[Current].+Power") | |
for line in lines.splitlines(): | |
if pattern.match(line): | |
name, value = re.split('\s+:\s+',line) | |
name = name.replace(" Power", "").lower() | |
value = value.replace(" Watts", "") | |
print "ipmi_power_usage_watts" + " " + value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment