xenstats |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/python
import sys
import os
import re
import time
if len(sys.argv)!=2:
print "Syntax: %s <rrdbasename>"%sys.argv[0]
sys.exit(1)
now=str(int(time.time()))
basename=sys.argv[1]
data=os.popen2("/usr/sbin/xm list")[1].read()
domains=data.split("\n")[1:-1]
for domain in domains:
name,id,mem,cpu,state,cputime=re.split("[\t ]+",domain)
cputime=int(float(cputime)*1000)
rrd=basename+name+".rrd"
if not os.access(rrd,os.F_OK):
#this should preserve rrd file reset when there is some problem
#time.sleep(10)
if not os.access(rrd,os.F_OK):
#time.sleep(10)
# 10 days of exact archive, 42 days of 1 hr RRD, 1000 days of 1 day RRD
os.system("rrdtool create "+rrd+" --step 60 DS:cpu:COUNTER:666:0:10000"+
" RRA:LAST:0.5:1:1500000"+
" RRA:MIN:0.5:60:1000 RRA:MIN:0.5:1440:1000"+
" RRA:MAX:0.5:60:1000 RRA:MAX:0.5:1440:1000"+
" RRA:AVERAGE:0.5:60:1000 RRA:AVERAGE:0.5:1440:1000")
#this should preserve rrd file reset when there is some problem
if os.access(rrd,os.F_OK):
os.system("rrdtool update %s %s:%s"%(rrd,now,cputime))