File: //opt/node_api/metrics.hook
#!/usr/bin/python
import os
import json
import re
def chomp(x):
if x.endswith("\r\n"): return x[:-2]
if x.endswith("\n"): return x[:-1]
return x
def io():
data = os.popen('/opt/node_api/io.hook').read()
print data.strip()
def get_data():
result={}
cpu={}
try:
data = os.popen('ipmi-sensors -h localhost --quiet-cache --sdr-cache-recreate --interpret-oem-data --output-sensor-state --ignore-not-available-sensors --comma-separated-output --no-header-output').readlines()
for line in data:
x = line.split(',')
if 'CPU' in line:
cpus = re.search('CPU(.*?) Temp', x[1], re.M | re.I)
if x[4]!="N/A":
print 'node_cpu{cpu="cpu' + cpus.group(1) + '",mode="temp"} ' + x[4]
if 'PCH Temp' in line:
print 'node_pch_temp ' + x[4]
if 'Peripheral Temp' in line:
print 'node_peripheral_temp ' + x[4]
if 'System Temp' in line:
print 'node_system_temp ' + x[4]
except:
return False
def main():
io()
if __name__ == "__main__":
main()