You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

62 lines
1.4 KiB

#! /usr/bin/env python
import subprocess
import sys
def f_parse(sens_out):
CPUN = 0
firstCPU = True
coreN = 0
dimm = "0"
ret = {}
line_sp = ""
for line in sens_out:
if "DIMM" in line:
line_sp = line.split()
dimm = "DIMM" + line_sp[1] + "-" + line_sp[3][0]
ret[dimm] = line_sp[4][1:-3]
elif "coretemp" in line:
if firstCPU:
firstCPU = False
else:
CPUN = CPUN + 1
elif "Core" in line:
line_sp = line.split()
coreN = "core" + str(CPUN) + "-" + line_sp[1][0]
ret[coreN] = line_sp[2][1:-3]
return(ret)
def f_sensors():
res = subprocess.Popen(['sudo sensors'], stdout=subprocess.PIPE, shell=True)
sensors_out = res.stdout.readlines()
return(sensors_out)
def f_main():
sensors_out = f_sensors()
sensors_parsed = f_parse(sensors_out)
return(sensors_parsed)
def f_json_print(inp):
first = True
print("{")
print("\t\"data\":[")
for key in inp:
if not first:
sys.stdout.write(",")
else:
first = False
sys.stdout.write("\n\t\t{\"{#SENSOR}\":\"" + key + "\"}")
print("\n\t]")
print("}")
if __name__ == '__main__':
out = {}
out = f_main()
if len(sys.argv) == 2 and sys.argv[1]:
print((out.get(sys.argv[1], "error")))
else:
f_json_print(out)

Powered by TurnKey Linux.