8 from datetime import datetime, timedelta
12 from nodecommon import color_pcu_state, datetime_fromstr
13 from nodehistory import get_filefromglob
19 # up with good hardware
20 # up with good hardware & functional pcu
22 #cm_url="http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name,cpuspeed,memsize,disksize'"
23 #cm = database.if_cached_else(1, "cmhardware", lambda : comon.comonget(cm_url))
25 def gethardwarequality(nodename, fb):
26 if nodename in fb['nodes'] and 'comonstats' in fb['nodes'][nodename]['values']:
27 cstat = fb['nodes'][nodename]['values']['comonstats']
28 for field in ['cpuspeed', 'memsize', 'disksize']:
29 if field not in cstat: cstat[field] = "null"
31 if cstat['cpuspeed'] != "null" and float(cstat['cpuspeed']) < 2.2:
32 return "BAD" # "cpu_slow",
33 if cstat['memsize'] != "null" and float(cstat['memsize']) < 2.8:
34 return "BAD" # "mem_small",
35 if cstat['disksize'] != "null" and float(cstat['disksize']) < 300.0:
36 return "BAD" # "disk_small",
38 if cstat['disksize'] == "null" and \
39 cstat['cpuspeed'] == "null" and \
40 cstat['memsize'] == "null":
44 if float(cstat['cpuspeed']) >= 2.2 and \
45 float(cstat['memsize']) >= 2.8 and \
46 (cstat['disksize'] == "null" or float(cstat['disksize']) >= 300.0):
55 def addtostats(stats, a):
56 if a['cc'] not in stats:
57 stats[a['cc']] = {'total' : 0,
62 stats[a['cc']]['total'] += 1
63 if a['status'] == "boot":
64 stats[a['cc']]['up'] += 1
65 if a['hardware'] == "A-OK":
66 stats[a['cc']]['goodhw'] += 1
67 if a['pcuok'] == "PCUOK " or a['pcuok'] == "PCUA-OK":
68 stats[a['cc']]['pcuok'] += 1
74 archive = database.SPickle(path)
82 begin = time.strftime(format)
84 d = datetime_fromstr(begin)
85 fbstr = get_filefromglob(d, "production.findbad")[0]
86 fbpcustr = get_filefromglob(d, "production.findbadpcus")[0]
88 l_plcnodes = database.dbLoad("l_plcnodes")
89 l_plcsites = database.dbLoad("l_plcsites")
90 lb2hn = database.dbLoad("plcdb_lb2hn")
91 fb = archive.load(fbstr)
92 fbpcu = archive.load(fbpcustr)
96 # COLLECT nodegroups, nodes and node lists
97 for site in l_plcsites:
99 if site['login_base'] in lb2hn:
100 nodes = lb2hn[site['login_base']]
102 hostname = node['hostname']
103 fields = hostname.split(".")
104 if len(fields[-1]) == 2:
106 elif fields[-1] == "edu":
108 elif site['login_base'] == "ft":
110 elif site['login_base'] == "ntu":
112 elif site['login_base'] in ["mcgill", "canarieottawa", 'canariecalgary',
113 'canariehalifax', 'canariemontreal',
114 'canarietoronto', 'canariewinnipeg']:
116 elif site['login_base'] in ["plcoloclarasanti", "plcoloclarasaopa",
117 "plcoloclarabueno", "plcoloclaratijua",
120 elif site['login_base'] in ["plcoloamst", 'cwi']:
122 elif site['login_base'] == "urv":
124 elif site['login_base'] == "ncl":
126 elif site['login_base'] == "waterford":
128 elif site['login_base'] in ["kisti", "snummlab"]:
130 elif site['login_base'] == "astri":
132 elif fields[-1] in [ "org", "net" ]:
134 elif fields[-1] == "com":
139 if hostname in fb['nodes']:
140 if 'state' in fb['nodes'][hostname]['values']:
141 state = fb['nodes'][hostname]['values']['state'].lower()
146 'site' : site['login_base'],
149 'hardware' : gethardwarequality(hostname, fb),
150 'pcuok' : color_pcu_state(fb['nodes'][hostname]['values']) }
153 # print fb['nodes'][hostname]['values']
154 results.append("%(cc)7s %(status)8s %(hardware)8s %(pcuok)8s %(site)15s %(host)42s " % args)
155 addtostats(stats, args)
157 site['latitude'] = -2
158 site['longitude'] = -2
160 #print "%4s %20s %8s %8s" % (CC, site['login_base'], site['latitude'], site['longitude'])
162 regions = { 'mideast' : ['cy', 'gr', 'il', 'in', 'lb', 'pk'],
164 'usa' : ['pr','us', 'uscom', 'usedu', 'usorg'],
165 'europe' : ['at','ch','cz','be', 'de', 'dk',
166 'es','fi', 'fr', 'hu', 'ie', 'is', 'it','nl',
167 'no', 'pl', 'pt', 'se', 'tr', 'uk'],
168 'asia' : ['cn','hk','jp','kr', 'ru', 'sg', 'si','tw',],
169 'australia': ['au', 'nz',],
170 'southam' : ['ar','br','southamerica','uy', 've'],
174 for key in regions.keys():
175 statsfold[key] = {'total' : 0, 'up' : 0,
176 'goodhw': 0, 'pcuok' : 0}
178 totaltotal = { 'total' : 0, 'up' : 0,
179 'goodhw': 0, 'pcuok' : 0}
180 # for all of the cc stats
181 for cc in stats.keys():
182 # search for the cc in the regions dict
183 for region in regions:
184 # if the cc is assigned to a region
185 if cc in regions[region]:
186 # add all values in cc stats to that region
187 for key in statsfold[region]:
188 statsfold[region][key] += stats[cc][key]
189 totaltotal[key] += stats[cc][key]
192 print " REGION | total | up |& goodhw |& pcuok "
193 for region in statsfold.keys():
194 statsfold[region]['region'] = region
195 print "%(region)13s | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % statsfold[region]
196 print " totals | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % totaltotal
199 print " Region | total | up |& goodhw |& pcuok "
200 for region in stats.keys():
201 stats[region]['region'] = region
202 print "%(region)13s | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % stats[region]
207 if __name__ == "__main__":