LandonWO LandonWO - 4 months ago 33
Python Question

Parsing temperature from lm_sensors command

Currently I'm using lm_sensors to get temperature information off of my server. I'd like to run a cron job that runs lm_sensors every five minutes, grabs the temperature data and puts it into a CSV file. However, I'm at a loss at how to parse the lm_sensors output. I'd like to parse it with either Python or bash as they're my most comfortable languages. I'm going to paste the current output of the lm_sensors command as as an example out the data I'm using. If someone could point me in the right direction on how to strip the data, I can figure the rest out from there. Thanks for the help.

Example output:

$ sensors
k10temp-pci-00c3
Adapter: PCI adapter
temp1: +0.0°C (high = +70.0°C, crit = +90.0°C)


atk0110-acpi-0
Adapter: ACPI interface
Vcore Voltage: +1.42 V (min = +0.85 V, max = +1.70 V)
+3.3 Voltage: +3.38 V (min = +2.97 V, max = +3.63 V)
+5 Voltage: +4.95 V (min = +4.50 V, max = +5.50 V)
+12 Voltage: +12.48 V (min = +10.20 V, max = +13.80 V)
CPU FAN Speed: 1510 RPM (min = 600 RPM)
CHASSIS FAN Speed: 1683 RPM (min = 600 RPM)
CPU Temperature: +37.0°C (high = +60.0°C, crit = +95.0°C)
MB Temperature: +25.0°C (high = +45.0°C, crit = +75.0°C)

Answer

If you want to use Python, use PySensors, but really don't re-invent the wheel. Set up any number of monitoring systems like cacti, munin and others and be done with it.