Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import re
from subprocess import check_output
from collections import namedtuple
TemperatureSensors = namedtuple('TemperatureSensors',
['cores', 'ambient', 'sodimm', 'fan'])
RE_CORES = r'Core\s+(\d+):\s+\+(\d+\.\d+).*C'
RE_AMBIENT = r'Ambient:\s+\+(\d+\.\d+).*C'
RE_SODIMM= r'SODIMM:\s+\+(\d+\.\d+).*C'
def sensors_temperature():
output = check_output("sensors")
tempSensors = TemperatureSensors()
# Parse cores temperature
tempSensors.cores = []
for match in re.finditer(RE_CORES, output):
core_id = int(
temperature = float(
assert len(tempSensors.cores) == core_id
# Get fan speed = int(, sensors).group(1))
# Get ambient temperature
tempSensors.ambient = float(, sensors).group(1))
# Get SODIMM temperature
tempSensors.sodimm = float(, sensors).group(1))
def cpu_frequencies():
freqs = []
for i in range(4):
output = check_output("cpufreq-info -c {} -f".format(i))
return freqs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment