#!/usr/bin/env python
#-*- coding:utf8 -*-
import requests
import time
import json
import scipy
from scipy import stats
# reference
# http://www.bkjia.com/Pythonjc/834245.html
# http://blog.csdn.net/cskchenshengkun/article/details/45790411
# http://www.168seo.cn/python/2379.html
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))
#print r.text
a = json.loads(r.text)
list = []
for b in a[0]['Values']:
if b['value'] > 0:
list.append(b['value'])
else:
#print b['value']
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)
python + falcon 处理cpu的 调和平均数
最新推荐文章于 2024-07-29 02:34:45 发布