3 from monitor.wrapper import plc, plccache
8 from datetime import datetime, timedelta
12 from monitor.common import color_pcu_state, datetime_fromstr, email_exception
13 from nodehistory import get_filefromglob
20 # up with good hardware
21 # up with good hardware & functional pcu
23 #cm_url="http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name,cpuspeed,memsize,disksize'"
24 #cm = database.if_cached_else(1, "cmhardware", lambda : comon.comonget(cm_url))
26 def gethardwarequality(nodename, fb):
27 if nodename in fb['nodes'] and 'comonstats' in fb['nodes'][nodename]['values']:
28 cstat = fb['nodes'][nodename]['values']['comonstats']
29 for field in ['cpuspeed', 'memsize', 'disksize']:
30 if field not in cstat: cstat[field] = "null"
32 if cstat['cpuspeed'] != "null" and float(cstat['cpuspeed']) < 2.2:
33 return "BAD" # "cpu_slow",
34 if cstat['memsize'] != "null" and float(cstat['memsize']) < 2.8:
35 return "BAD" # "mem_small",
36 if cstat['disksize'] != "null" and float(cstat['disksize']) < 300.0:
37 return "BAD" # "disk_small",
39 if cstat['disksize'] == "null" and \
40 cstat['cpuspeed'] == "null" and \
41 cstat['memsize'] == "null":
45 if float(cstat['cpuspeed']) >= 2.2 and \
46 float(cstat['memsize']) >= 2.8 and \
47 (cstat['disksize'] == "null" or float(cstat['disksize']) >= 300.0):
56 def addtostats(stats, a):
57 if a['cc'] not in stats:
58 stats[a['cc']] = {'total' : 0,
63 stats[a['cc']]['total'] += 1
64 if a['status'] == "boot":
65 stats[a['cc']]['up'] += 1
66 if a['hardware'] == "A-OK":
67 stats[a['cc']]['goodhw'] += 1
68 if a['pcuok'] == "PCUOK " or a['pcuok'] == "PCUA-OK":
69 stats[a['cc']]['pcuok'] += 1
75 archive = database.SPickle(path)
83 begin = time.strftime(format)
85 d = datetime_fromstr(begin)
86 fbstr = get_filefromglob(d, "production.findbad")[0]
87 fbpcustr = get_filefromglob(d, "production.findbadpcus")[0]
89 l_plcnodes = plccache.l_nodes
90 l_plcsites = plccache.l_sites
91 lb2hn = plccache.plcdb_lb2hn
92 fb = archive.load(fbstr)
93 fbpcu = archive.load(fbpcustr)
97 # COLLECT nodegroups, nodes and node lists
98 for site in l_plcsites:
100 if site['login_base'] in lb2hn:
101 nodes = lb2hn[site['login_base']]
103 hostname = node['hostname']
104 fields = hostname.split(".")
105 if len(fields[-1]) == 2:
107 elif fields[-1] == "edu":
109 elif site['login_base'] == "ft":
111 elif site['login_base'] == "ntu":
113 elif site['login_base'] in ["mcgill", "canarieottawa", 'canariecalgary',
114 'canariehalifax', 'canariemontreal',
115 'canarietoronto', 'canariewinnipeg']:
117 elif site['login_base'] in ["plcoloclarasanti", "plcoloclarasaopa",
118 "plcoloclarabueno", "plcoloclaratijua",
121 elif site['login_base'] in ["plcoloamst", 'cwi']:
123 elif site['login_base'] == "urv":
125 elif site['login_base'] == "ncl":
127 elif site['login_base'] == "waterford":
129 elif site['login_base'] in ["kisti", "snummlab"]:
131 elif site['login_base'] == "astri":
133 elif fields[-1] in [ "org", "net" ]:
135 elif fields[-1] == "com":
140 if hostname in fb['nodes']:
141 if 'state' in fb['nodes'][hostname]['values']:
142 state = fb['nodes'][hostname]['values']['state'].lower()
147 'site' : site['login_base'],
150 'hardware' : gethardwarequality(hostname, fb),
151 'pcuok' : color_pcu_state(fb['nodes'][hostname]['values']) }
153 # print traceback.print_exc()
155 # print fb['nodes'][hostname]['values']
156 results.append("%(cc)7s %(status)8s %(hardware)8s %(pcuok)8s %(site)15s %(host)42s " % args)
157 addtostats(stats, args)
159 site['latitude'] = -2
160 site['longitude'] = -2
162 #print "%4s %20s %8s %8s" % (CC, site['login_base'], site['latitude'], site['longitude'])
164 regions = { 'mideast' : ['cy', 'gr', 'il', 'in', 'lb', 'pk'],
166 'usa' : ['pr','us', 'uscom', 'usedu', 'usorg'],
167 'europe' : ['at','ch','cz','be', 'de', 'dk',
168 'es','fi', 'fr', 'hu', 'ie', 'is', 'it','nl',
169 'no', 'pl', 'pt', 'se', 'tr', 'uk'],
170 'asia' : ['cn','hk','jp','kr', 'ru', 'sg', 'si','tw',],
171 'australia': ['au', 'nz',],
172 'southam' : ['ar','br','southamerica','uy', 've'],
176 for key in regions.keys():
177 statsfold[key] = {'total' : 0, 'up' : 0,
178 'goodhw': 0, 'pcuok' : 0}
180 totaltotal = { 'total' : 0, 'up' : 0,
181 'goodhw': 0, 'pcuok' : 0}
182 # for all of the cc stats
183 for cc in stats.keys():
184 # search for the cc in the regions dict
185 for region in regions:
186 # if the cc is assigned to a region
187 if cc in regions[region]:
188 # add all values in cc stats to that region
189 for key in statsfold[region]:
190 statsfold[region][key] += stats[cc][key]
191 totaltotal[key] += stats[cc][key]
194 print " REGION | total | up |& goodhw |& pcuok "
195 for region in statsfold.keys():
196 statsfold[region]['region'] = region
197 print "%(region)13s | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % statsfold[region]
198 print " totals | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % totaltotal
201 print " Region | total | up |& goodhw |& pcuok "
202 for region in stats.keys():
203 stats[region]['region'] = region
204 print "%(region)13s | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % stats[region]
209 if __name__ == "__main__":