1 | 1 | simandl | #!/usr/bin/python |
2 | | | import sys |
3 | | | import os |
4 | | | import re |
5 | | | import time |
6 | | | |
7 | | | if len(sys.argv)!=2: |
8 | | | print "Syntax: %s <rrdbasename>"%sys.argv[0] |
9 | | | sys.exit(1) |
10 | | | |
11 | | | now=str(int(time.time())) |
12 | | | basename=sys.argv[1] |
13 | | | data=os.popen2("/usr/sbin/xm list")[1].read() |
14 | | | domains=data.split("\n")[1:-1] |
15 | | | for domain in domains: |
16 | | | name,id,mem,cpu,state,cputime=re.split("[\t ]+",domain) |
17 | | | cputime=int(float(cputime)*1000) |
18 | | | rrd=basename+name+".rrd" |
19 | | | if not os.access(rrd,os.F_OK): |
20 | 3 | simandl | #this should preserve rrd file reset when there is some problem |
21 | | | time.sleep(10) |
22 | | | if not os.access(rrd,os.F_OK): |
23 | | | # 10 days of exact archive, 42 days of 1 hr RRD, 1000 days of 1 day RRD |
24 | | | os.system("rrdtool create "+rrd+" --step 60 DS:cpu:COUNTER:666:0:10000"+ |
25 | | | " RRA:LAST:0.5:1:15000"+ |
26 | | | " RRA:MIN:0.5:60:1000 RRA:MIN:0.5:1440:1000"+ |
27 | | | " RRA:MAX:0.5:60:1000 RRA:MAX:0.5:1440:1000"+ |
28 | | | " RRA:AVERAGE:0.5:60:1000 RRA:AVERAGE:0.5:1440:1000") |
29 | | | |
30 | | | #this should preserve rrd file reset when there is some problem |
31 | | | if os.access(rrd,os.F_OK): |
32 | | | os.system("rrdtool update %s %s:%s"%(rrd,now,cputime)) |
33 | 1 | simandl | |