首页 > 代码库 > getrrdinfo.py

getrrdinfo.py

#!/usr/bin/env python# coding=gbkimport sysimport osimport timeif __name__== __main__:    filename = sys.argv[1]    nowtime = int(time.time())    starttime = nowtime - 60    cmd = "rrdtool fetch "+filename+" AVERAGE --start " + str(starttime) + " --end "+str(nowtime)#    print cmd    values = []    f = os.popen(cmd)    for res in f:        if res.find(":") == -1:            continue        if res.find("nan") != -1:            continue        values.append(eval(res.split(:)[1].strip().split( )[0].strip()))#    print values     res = 0.0    for v in values:        res = res + v    if len(values) == 0:        res = 0.0    else:        res = res/len(values)    print "value:"+str(res)