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'
RE_FAN=r'Processor\s+Fan:\s+(\d+)\s+RPM'
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(match.group(1))
temperature = float(match.group(2))
assert len(tempSensors.cores) == core_id
tempSensors.cores.append(temperature)
# Get fan speed
tempSensors.fan = int(re.search(RE_FAN, sensors).group(1))
# Get ambient temperature
tempSensors.ambient = float(re.search(RE_AMBIENT, sensors).group(1))
# Get SODIMM temperature
tempSensors.sodimm = float(re.search(RE_SODIMM, sensors).group(1))
def cpu_frequencies():
freqs = []
for i in range(4):
output = check_output("cpufreq-info -c {} -f".format(i))
freqs.append(int(output))
return freqs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment