Skip to content

Instantly share code, notes, and snippets.

@sergeyfedotov
Last active February 9, 2017 13:50
Show Gist options
  • Select an option

  • Save sergeyfedotov/bd695d80edbad86ad4c544197bf0c007 to your computer and use it in GitHub Desktop.

Select an option

Save sergeyfedotov/bd695d80edbad86ad4c544197bf0c007 to your computer and use it in GitHub Desktop.
Indicator for Asus G56JR (i7-4700HQ), Ubuntu 16.04
import psutil as ps
from os import popen
def get_mem_usage():
mem_total = None
mem_available = None
with open('/proc/meminfo') as f:
for line in f:
if line.startswith('MemTotal:'):
mem_total = int(line.split()[1])
elif line.startswith('MemAvailable:'):
mem_available = int(line.split()[1])
if mem_total is None or mem_available is None:
return None
return mem_total - mem_available
def get_cpu_info():
cpu_usage = ps.cpu_percent(interval=3, percpu=False)
fan_speed = None
cpu_temp = None
with popen('sensors asus-isa-0000') as f:
for line in f:
if line.startswith('cpu_fan:'):
fan_speed = int(line.split()[1])
elif line.startswith('temp1:'):
cpu_temp = line.split()[1]
cpu_speed = None
with popen('lscpu') as f:
for line in f:
if line.startswith('CPU MHz:'):
cpu_speed = float(line.split()[2]) / 1000
return {
'cpu_usage': cpu_usage,
'cpu_speed': cpu_speed,
'cpu_temp': cpu_temp,
'fan_speed': fan_speed
}
if __name__ == '__main__':
cpu_info = get_cpu_info()
print("{mem:5.1f}GB {cpu:5.1f}% {spd:4.1f}GHz {temp} {fan:4d}RPM".format(
mem=get_mem_usage() / 1024 / 1024,
cpu=cpu_info['cpu_usage'],
spd=cpu_info['cpu_speed'],
temp=cpu_info['cpu_temp'],
fan=cpu_info['fan_speed']
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment