您的位置:首页 > 其它

使用zabbix API估算服务器磁盘空间可用天数

2015-09-07 16:53 309 查看
代码github位置。主要功能:获取zabbix某个分组下的所有机器,计算这些机器的磁盘剩余空间按照“自然”增长还可以使用多少天。主要流程:获取某个group下所有机器。
def host_get_by_groupid(self,groupid):
data = json.dumps(
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output":"shorten",
"groupids":groupid,
},
"auth": self.authID,
"id": 1,
})
res = self.get_data(data)['result']

对这些机器获取历史上X天的某一个时间点的磁盘剩余空间。
def history_get(self,itemid,time_from):
data = json.dumps(
{
"jsonrpc": "2.0",
"method": "history.get",
"params": {
"itemids": [itemid],
"time_from": time_from,
"output": "extend",
"sortorder": "ASC",
"limit": "1"
},
"auth": self.authID,
"id": 1
})
res = self.get_data(data)['result']
log.debug(res)
if (res != 0) and (len(res) == 1):
return res[0]
else:
return {"value":-1,"clock":time_from}

使用2的数据算出每天的decrease值;去掉2个最大值;剩余的值中如果decrease是正数的天数超过一半天数时,使用这些正数值求一个平均值。
#if the decrease if more than increase, maybe they have a crontab to relase space.
#like this 5 4 5 4 5 4

当前剩余空间/平均值,得到最终结果。

目的:
掌握使用python访问zabbix API。

为了更“现实”的做好容量规划。

参考:
#base from http://wangwei007.blog.51cto.com/68019/1249770 #The API document https://www.zabbix.com/documentation/1.8/api[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息