import requests
import time
import json
import scipy
from scipy import stats
thistime = int(time.time())
start = thistime - 3600 * 24 *3
def getData(start,end,endpoint,counter):
d = {
"start": start,
"end": end,
"cf": "AVERAGE",
"endpoint_counters": [
{
"endpoint": "%s"%endpoint,
"counter": "%s"%counter,
},
],
}
query_api = "http://192.168.0.110:9966/graph/history"
r = requests.post(query_api, data=json.dumps(d))
a = json.loads(r.text)
list = []
for b in a[0]['Values']:
if b['value'] > 0:
list.append(b['value'])
else:
pass
return list
def getAvg(day,endpoint,metric,incr=0):
end = int(time.time())
start = end - 3600 * 24 * day
list = getData(start,end,endpoint,metric)
if incr == 1:
list = difflist(list)
print "调和平均数:%s"%(stats.hmean(list))
getAvg(1,"192.168.0.177","df.bytes.used.percent/fstype=ext4,mount=/",incr=1)
getAvg(3,"192.168.0.177","df.bytes.used.percent/fstype=ext4,mount=/",incr=1)
getAvg(15,"192.168.0.177","df.bytes.used.percent/fstype=ext4,mount=/",incr=1)