Created
November 8, 2011 04:18
-
-
Save alexalemi/1346984 to your computer and use it in GitHub Desktop.
Ruptime CGI-Script
This file contains 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 cgi | |
import os | |
from collections import namedtuple | |
uptime_tuple= namedtuple('uptime','up time users load_1 load_5 load_15') | |
hosts = ['ept','dain','heveled','kempt','gruntled'] | |
def uptime_processor(str, hosts=hosts): | |
try: | |
st = [ x.rstrip(',') for x in str.split() ] | |
#e.g. ['kempt', 'up', '157+01:29', '0', 'users', 'load', '7.17', '7.07', '7.02'] | |
#inds 0 1 2 3 4 5 6 7 8 | |
tup = uptime_tuple( st[1] , st[2], int(st[3]), float(st[6]), float(st[7]), float(st[8]) ) | |
if st[0] in hosts: | |
return (st[0], tup ) | |
except IndexError: | |
pass | |
rupres = os.popen('ruptime') | |
rupgood = dict(filter(None,[ uptime_processor(line) for line in rupres ])) | |
num_processors = { 'dain': 16, 'kempt': 16, 'heveled': 16, 'ept': 16 , 'gruntled': 8, 'Cerbo': 4 } | |
def rupcmp(one,two): | |
val_one = one[1].load_15/num_processors[one[0]] | |
val_two = two[1].load_15/num_processors[one[0]] | |
return cmp( val_one, val_two ) | |
def load_to_percent(host,tup): | |
mn = 0 | |
mx = 100 | |
val = comp[1].load_15*1.0/num_processors[host]*mx | |
if val > mx: | |
return mx | |
elif val < mn: | |
return mn | |
else: | |
return val | |
def load_to_color(host,tup): | |
mn = 0 | |
mx = 256 | |
val = min( int( tup.load_15*1.0/num_processors[host]*mx), 255 ) | |
colints = ( val, 0 , 256 - val ) | |
colstring = "%02x%02x%02x" % colints | |
return colstring | |
sorted_rup_result = sorted( rupgood.iteritems() , cmp=rupcmp ) | |
print "Content-Type: text/html" | |
print "<html> <head> <title> Sethna ruptime </title> </head> <link href='../style.css' rel='stylesheet' type='text$ | |
print "<p> Status of the Sethna machines </p> " | |
print "<center><table cellpadding='10' cellspacing='10'><tr id='head'> <td> Host <td> Status <td> Uptime <td> User$ | |
for comp in sorted_rup_result: | |
print "<tr><td> {host} <td> {t.up} <td> {t.time} <td> {t.users} <td> {t.load_1} <td> {t.load_5} <td> {t.load_1$ | |
print "<tr><td colspan=7> <div style='border: 1px solid grey;'> <div style='background-color: #{color}; width$ | |
print "</table>" | |
print "<p>The above represents the status of the CCMR machines. Shows the status, how long the computer has been $ | |
print "</center>" | |
print "</body></html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment