python + falcon 处理cpu的 调和平均数

#!/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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值