Skip to content

Instantly share code, notes, and snippets.

@sleepynate
Created October 15, 2010 15:18
Show Gist options
  • Save sleepynate/628362 to your computer and use it in GitHub Desktop.
Save sleepynate/628362 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
class cpu_info:
def __init__(self):
self.user = 0
self.sys = 0
self.idle = 0
self.iowait = 0
def copy(self,inf):
self.user = inf.user
self.sys = inf.sys
self.idle = inf.idle
self.iowait = inf.iowait
if __name__ == '__main__':
import time, subprocess
old = cpu_info()
new = cpu_info()
master = cpu_info()
dzenProc = subprocess.Popen(("dzen2 -p -ta c -h 16 -bg '#2f2f2f' -x 320 -y 0 -w 60 -sa c -e button3=exit -xs 0 -fn '-*-mintsmild-*-r-*-*-11-*-*-*-*-*-*-*'"), shell=True, stdin=subprocess.PIPE)
while 1:
f = file("/proc/stat","r")
fcon = f.read().split("\n")[0].split()
new.user, unice, new.sys, new.idle, new.iowait = [
int(x) for x in fcon[1:6] ]
new.user += unice
master.user = new.user - old.user
master.sys = new.sys - old.sys
master.idle = new.idle - old.idle
master.iowait = new.iowait - old.iowait
maxval = master.user + master.sys + master.idle + master.iowait
curval = master.user + master.sys + master.iowait
old.copy(new)
dzenProc.stdin.write("^tw() ^fg(#dfdfdf) ^i(/usr/share/xbms/cpu.xbm) : %d%%\n" % ( (float(curval)/maxval) * 100 ))
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment