Created
October 31, 2011 18:12
-
-
Save fuzzy/1328281 to your computer and use it in GitHub Desktop.
This is a quick recipe for a simple 'top' for watching DistCC. I know there's distccmon-text, but I prefer a 'top'-like display.
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 os, sys, time | |
import curses,struct | |
states = ['STARTUP', 'BLOCKED', 'CONNECT', 'PREPROCESS', 'SEND', 'COMPILE', 'RECEIVE', 'DONE'] | |
DISTCC_DIR = os.getenv('DISTCC_DIR') or '%s/.distcc' % os.getenv('HOME') | |
def getStats(scr): | |
curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK) | |
curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK) | |
curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK) | |
(maxY, maxX) = scr.getmaxyx() | |
while 1: | |
try: | |
scr.addstr(0, 0, time.ctime()) | |
scr.addstr(1, 0, 'System Load: %s' % (str(os.getloadavg())[1:][:-1])) | |
scr.addstr(3, 0, '%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD|curses.A_REVERSE) | |
cnt = 5 | |
try: | |
for i in os.listdir(DISTCC_DIR+'/state'): | |
data = struct.unpack('@iLL128s128siiP', open(DISTCC_DIR+'/state/'+i).readline().strip()) | |
file = data[3].split('\x00')[0] or 'None' | |
host = data[4].split('\x00')[0] or 'None' | |
slot = int(data[5]) | |
stte = states[int(data[6])] | |
if 'None' not in (file, host): | |
scr.addstr(cnt, 0, '%4d %-20s ' % (slot, host)) | |
if int(data[6]) in (2,3): | |
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(10)) | |
elif int(data[6]) in (0,1): | |
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(11)) | |
elif int(data[6]) in (4,5): | |
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(12)) | |
elif int(data[6]) in (6,7): | |
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(12)|curses.A_BOLD) | |
else: scr.addstr(cnt, 26, '%-15s ' % (stte)) | |
scr.addstr(cnt, 42, '%-40s%s' % (file, ' '*(maxX-83))) | |
cnt += 1 | |
except struct.error: pass | |
except IOError: pass | |
scr.refresh() | |
time.sleep(0.75) | |
scr.erase() | |
scr.move(0,0) | |
except KeyboardInterrupt: | |
sys.exit(-1) | |
if __name__ == '__main__': | |
curses.wrapper(getStats) |
Now with color, respect for terminal sizes (init not resizes), and 10% less sodium!!! SWEET JESUS!@!#!TY
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And before you chide me, yes I know I just pass on struct errors so I'm not getting 100% accuracy in the reporting, but honestly....I'm ok with that, I just want to know that distcc is farming out jobs appropriately for the most part, and was bored and wanted to do a little something with curses.