使用zabbix API估算服务器磁盘空间可用天数
代码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 #The API document https://www.zabbix.com/documentation/1.8/api温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67618.html