4 from monitor import config
5 from monitor.wrapper import plc
6 from monitor import parser as parsermodule
7 from monitor.model import *
8 from monitorstats import *
9 from monitor import database
14 from datetime import datetime, timedelta
16 from nodequeryold import verify,query_to_dict,node_select
18 api = plc.getAuthAPI()
20 def nodes_from_time(arch, file):
23 nodelist = fb['nodes'].keys()
24 nodelist = node_select(config.select, nodelist, fb)
29 parser = parsermodule.getParser()
30 parser.set_defaults(archivedir='archive-pdb', begin=None, end=None, select=None)
31 parser.add_option("", "--archivedir", dest="archivedir", metavar="filename",
32 help="Pickle file aggregate output.")
33 parser.add_option("", "--select", dest="select", metavar="key",
35 parser.add_option("", "--begin", dest="begin", metavar="YYYY-MM-DD",
36 help="Specify a starting date from which to begin the query.")
37 parser.add_option("", "--end", dest="end", metavar="YYYY-MM-DD",
38 help="Specify a ending date at which queries end.")
39 config = parsermodule.parse_args(parser)
40 archive = get_archive(config.archivedir)
42 if not config.begin or not config.end:
43 print parsermodule.usage(parser)
47 d_s1 = datetime_fromstr(config.begin)
48 d_s2 = datetime_fromstr(config.begin) + tdelta
49 d_end = datetime_fromstr(config.end)
54 f_s1 = get_filefromglob(d_s1, "production.findbad", config.archivedir)
55 f_s2 = get_filefromglob(d_s2, "production.findbad", config.archivedir)
57 s1 = set(nodes_from_time(archive, f_s1))
58 s2 = set(nodes_from_time(archive, f_s2))
60 print "[ %s, %s, %s ]," % ( len(s2), len(s2-s1), len(s1-s2) )
61 data.append( [ len(s2), len(s2-s1), len(s1-s2)] )
63 #print "len s2 : ", len(s2)
64 #print "len s1 : ", len(s1)
65 #print "%s nodes up" % len(s2-s1)
66 #print "Nodes s2 minus s1: len(s2-s1) = %s" % len(s2-s1)
67 #for node in s2 - s1: print node
69 #print "%s nodes down" % len(s1-s2)
70 #print "Nodes s1 minus s2: len(s1-s2) = %s" % len(s1-s2)
71 # for node in s1 - s2: print node
83 s1 = map(lambda x: x-500, s1)
86 diff_low = map(lambda x: x[0]-x[1], rlow)
87 diff_high = map(lambda x: x[0]+x[1], rhigh)
88 s1 = map(lambda x: str(x), s1)
89 diff_low = map(lambda x: str(x), diff_low)
90 diff_high = map(lambda x: str(x), diff_high)
94 print "http://chart.apis.google.com/chart?cht=lc&chds=40,100&chxt=x,y&chxl=0:|Oct|Nov|Dec|Jan|Feb|1:|540|580|600&chs=700x200&chm=F,aaaaaa,1,-1,2&chd=t1:%s" % ",".join(s1) + "|" + ",".join(diff_low) + "|" + ",".join(s1) + "|" + ",".join(s1) +"|" + ",".join(diff_high)
96 # takes two arguments as dates, comparing the number of up nodes from one and
99 if __name__ == "__main__":