Created
October 27, 2011 13:34
-
-
Save jiphex/1319546 to your computer and use it in GitHub Desktop.
Generate a rolling bar graph of load average
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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