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, select=None):
23 nodelist = fb['nodes'].keys()
24 nodelist = node_select(select, nodelist, fb)
27 def print_nodelist(nodelist, file):
36 parser = parsermodule.getParser()
37 parser.set_defaults(archivedir='archive-pdb', begin=None, end=None, printnodes=False, select=None, select2=None)
38 parser.add_option("", "--archivedir", dest="archivedir", metavar="filename",
39 help="Pickle file aggregate output.")
40 parser.add_option("", "--select", dest="select", metavar="key",
42 parser.add_option("", "--select2", dest="select2", metavar="key",
44 parser.add_option("", "--print", dest="printnodes", action="store_true",
45 help="print the nodes that have come up or down.")
46 parser.add_option("", "--begin", dest="begin", metavar="YYYY-MM-DD",
47 help="Specify a starting date from which to begin the query.")
48 parser.add_option("", "--end", dest="end", metavar="YYYY-MM-DD",
49 help="Specify a ending date at which queries end.")
50 config = parsermodule.parse_args(parser)
51 archive = get_archive(config.archivedir)
53 if not config.begin or not config.end:
54 print parsermodule.usage(parser)
58 d_s1 = datetime_fromstr(config.begin)
59 d_s2 = datetime_fromstr(config.begin) + tdelta
60 d_end = datetime_fromstr(config.end)
70 f_s1 = get_filefromglob(d_s1, "production.findbad", config.archivedir)
71 f_s2 = get_filefromglob(d_s2, "production.findbad", config.archivedir)
73 timestr = d_s2.strftime("%Y-%m-%d")
74 print timestr, ",", 0, ",", 0
79 s1 = set(nodes_from_time(archive, f_s1, config.select))
80 s2 = set(nodes_from_time(archive, f_s2, config.select))
81 s3 = set(nodes_from_time(archive, f_s2, config.select2))
84 timestr = d_s2.strftime("%Y-%m-%d")
85 print timestr, ",", len(s2),",", len(s3)
86 if not config.printnodes:
87 # f_up = open("up-%s" % timestr, 'w')
88 # f_down = open("dn-%s" % timestr, 'w')
93 print "%s nodes up" % len(s2-s1)
94 print "Nodes s2 minus s1: len(s2-s1) = %s" % len(s2-s1)
98 #print_nodelist(s2-s1, f_up)
100 if config.printnodes:
102 print "%s nodes down" % len(s1-s2)
103 print "Nodes s1 minus s2: len(s1-s2) = %s" % len(s1-s2)
105 #print_nodelist(s1-s2, f_down)
106 if not config.printnodes:
107 if f_up: f_up.close()
108 if f_up: f_down.close()
121 s1 = map(lambda x: x-500, s1)
124 diff_low = map(lambda x: x[0]-x[1], rlow)
125 diff_high = map(lambda x: x[0]+x[1], rhigh)
126 s1 = map(lambda x: str(x), s1)
127 diff_low = map(lambda x: str(x), diff_low)
128 diff_high = map(lambda x: str(x), diff_high)
132 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)
134 # takes two arguments as dates, comparing the number of up nodes from one and
137 if __name__ == "__main__":