1 | 1 | simandl | #!/usr/bin/python |
2 | | | import sys |
3 | | | import os |
4 | | | import glob |
5 | | | import time |
6 | | | |
7 | | | if len(sys.argv)!=2: |
8 | | | print "Syntax: %s <rrdbasename>"%sys.argv[0] |
9 | | | sys.exit(1) |
10 | | | |
11 | | | colors=["000000", "FF0000", "00FF00", "0000FF" ] |
12 | | | colors+=["DEDE00", "00FFFF", "FF90FF", "FF8040", "C040A0", "A0A0A0", "40A0A0", "40A0FF", "FFA040" ] |
13 | | | |
14 | | | def graph(basename, subname, seconds): |
15 | | | rrds=glob.glob(basename+"*.rrd") |
16 | | | rrds=[x for x in rrds if os.stat(x)[8] > (time.time()-seconds)] |
17 | | | |
18 | | | cmdline="--imgformat PNG --unit % --vertical-label CPU% " |
19 | | | #cmdline="--imgformat PNG --unit % --vertical-label CPU% --rigid --lower-limit 0 --upper-limit 100 " |
20 | | | |
21 | | | for rrd,id in zip(rrds,range(len(rrds))): |
22 | | | cmdline+="DEF:id%draw=%s:cpu:LAST "%(id,rrd) |
23 | | | cmdline+="CDEF:id%dpercent=id%draw,10,/ "%(id,id) |
24 | | | cmdline+="CDEF:id%dzero=id%dpercent,DUP,UN,EXC,0,EXC,IF "%(id,id) |
25 | | | for rrd,id in zip(rrds,range(len(rrds))): |
26 | | | cmdline+="%s:id%dzero#%s:%s "%({0:"AREA"}.get(id,"STACK"),id,colors[id%len(colors)],rrd[len(basename):-4]) |
27 | | | cmdline+="GPRINT:id%dpercent:AVERAGE:\"%s\" "%(id,"Average CPU usage\: %02.0lf%%\\j") |
28 | | | |
29 | | | # print cmdline |
30 | | | os.system("rrdtool graph %s../graph/xen-%s.png --start -%d --end -69 %s"%(basename,subname,seconds,cmdline)) |
31 | | | |
32 | | | basename=sys.argv[1] |
33 | | | graph(basename, "hourly", 4000) |
34 | | | graph(basename, "daily", 100000) |
35 | | | graph(basename, "weekly", 800000) |
36 | | | graph(basename, "monthly", 3200000) |
37 | | | graph(basename, "yearly", 40000000) |
38 | | | |