Skip to content

Instantly share code, notes, and snippets.

@jiphex
Created October 27, 2011 13:34
Show Gist options
  • Save jiphex/1319546 to your computer and use it in GitHub Desktop.
Save jiphex/1319546 to your computer and use it in GitHub Desktop.
Generate a rolling bar graph of load average
#!/usr/bin/env python
import time
import sys
CEILING=10
WIDTH=80
def get_loadavg():
f = open('/proc/loadavg','r')
line = f.read()
f.close()
l1 = line.split(" ")[0]
return float(l1)
while True:
l1 = get_loadavg()
prefix = ""
if(len(sys.argv) > 1 and sys.argv[1] == "-p"):
loadf = "%03.3f" % l1
prefix = loadf +": "
LWIDTH=WIDTH-len(prefix)
else:
LWIDTH=WIDTH
nbars = int(LWIDTH*(float(l1/CEILING)))
print prefix+nbars*"#"
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment