python脚本 + falcon数据 = 测算磁盘是否满足需求

  • 随着业务的上量,日志的增加,最先达到硬件资源瓶颈的也许就是硬盘,传统的手工观察磁盘监控曲线图直观,大方,但是多机器的时候就有点累了;而且单纯靠人测算的很有误差。

手工计算

这里写图片描述

脚本 根据一天数据计算

这里写图片描述

脚本 根据三天数据计算

这里写图片描述

脚本如下

#!/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

# 定义获得指定取件的数值
def getData(start,end,endpoint,counter,incr=0):
    d = {
        "start": start,
        "end": end,
        "cf": "AVERAGE",
        "endpoint_counters": [
            {
                "endpoint": "%s"%endpoint,
                "counter": "%s"%counter,
            },
            ],
        }

    query_api = "http://xxx:9966/graph/history"
    r = requests.post(query_api, data=json.dumps(d))
    #print r.text
    a = json.loads(r.text)
    #print a
    valueinterval = (a[0]['Values'][1]['timestamp'] - a[0]['Values'][0]['timestamp'])/60
    print valueinterval
    list = []
    for b in a[0]['Values']:
        if b['value'] > 0:
            list.append(b['value']/valueinterval)
        else:
            #print b['value']
            pass
    # 如果incr是1,那么再加一步骤,做个differ
    if incr == 1:
       list1 = [] 
       for i in range(1,len(list)):
           differValue = list[i] - list[i-1]
           if differValue > 0:
               list1.append(differValue)
       #print list
       #print list1
       list = list1
    return list

# 求 调和平均数
def getAvg(day,endpoint,metric,incr=0):
    end = int(time.time())
    start = end - 3600 * 24 * day
    list = getData(start,end,endpoint,metric,incr)
    #print "主机:%s 指标:%s的增长率是:"%(endpoint,metric),
    #print "调和平均数:%s"%(stats.hmean(list))
    return stats.hmean(list)
    #return stats.gmean(list)

# 获取过去一天的数据
def userDefine(day,ips,metric,incr=0):
    result = []
    for ip in ips:
        value = getAvg(day,ip,metric,incr)
        result.append(value)
    return result

ips = []
ips.append("10.0.100.85")
day = 3

result1 = []
metric = "df.bytes.used.percent/fstype=ext4,mount=/"
result1=userDefine(day,ips,metric,1)

result2 = []
metric = "df.bytes.used/fstype=ext4,mount=/"
result2=userDefine(day,ips,metric,1)

print ips

print result1

print result2

print """ 
| 主机 | 磁盘占用/分钟(%) | 磁盘占用/小时(%)| 磁盘占用/天(%)| 磁盘新增占用/分钟(Byte)| 磁盘新增占用/分钟(KByte) |磁盘新增占用/小时(KByte) | 存储7天需要(GByte) | 目前量可以维持几天 |
| -- | -- |-- |-- |-- |-- | -- |-- | -- |"""
for i in range(0,len(ips)):
    print """| %s | %s | %s | %s | %s | %s | %s | %s | %s |"""%(ips[i],round(result1[i],5),round(result1[i],5)*60,round(result1[i],5)*1440,round(result2[i],2),round(result2[i],2)*60,round(result2[i],2)*1440, round(result2[i]*1440*7/1000/1000/1000,0),round(80/result1[i]/1440))

哈哈,多了一个武器,下次再测算就方便多了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值