import os, json, requests, time
def get_disk_peak(ip):
# 拼接URL
pre_url = 'http://10.xx.5.3x:90x0' + '/api/v1/query?query='
expr = '(node_filesystem_size_bytes{fstype!~"apfs",mountpoint="/",instancehost="ip17"} - node_filesystem_free_bytes{fstype!~"apfs",mountpoint="/",instancehost="ip17"}) / node_filesystem_size_bytes{fstype!~"apfs",mountpoint="/",instancehost="ip17"} * 100'.replace('ip17', ip)
url = pre_url + expr
result = {}
# 请求URL后将Json数据转为字典对象
res = json.loads(requests.post(url=url).content.decode('utf8', 'ignore'))
print("###json:", res)
# 循环取出字典里每个IP的values,排序取最高值,最后存入result字典
result_list = res.get('data').get('result')
print(result_list)
result_dict = result_list[0]
result_value = result_dict['value']
return result_value[1]
def get_rule_recovery(ip, recovery_expr):
# 拼接URL
pre_url = 'http://10.xx.5.3x:9xx0' + '/api/v1/query?query='
expr = recovery_expr.replace('ip17', ip)
url = pre_url + expr
# 请求URL后将Json数据转为字典对象
res = json.loads(requests.post(url=url).content.decode('utf8', 'ignore'))
print("###json:", res)
result_list = res.get('data').get('result')
print(result_list)
result_dict = result_list[0]
result_value = result_dict['value']
return result_value[1]
ww = '(node_filesystem_size_bytes{fstype!~"apfs",mountpoint="/",instancehost="ip17"} - node_filesystem_free_bytes{fstype!~"apfs",mountpoint="/",instancehost="ip17"}) / node_filesystem_size_bytes{fstype!~"apfs",mountpoint="/",instancehost="ip17"} * 100'
print(get_rule_recovery(ip='10.31.140.24', recovery_expr=ww))
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。