python3调用|python3调用 prometheus API
import os, json, requests, timedef 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 = https://www.it610.com/article/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 = https://www.it610.com/article/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))
【python3调用|python3调用 prometheus API】
文章图片
推荐阅读
- elasticsearch api 调用
- Swift|Swift 百度API调用及json解析
- 干货|干货 | 用python3+dlib教你的程序察言观色
- Mac下使用HomeBrew安装python3
- 前端html|Vue3调用高德地图
- 高德地图|vue项目中调用高德地图vue-amap 插件 的AMap.PlaceSearch简用
- 六|6.1_4 Python3.x入门 P4 【基础】可变序列(列表list、字典dict、集合set)
- 六|6.1_2 Python3.x入门 P2 【基础】运算符
- 六|6.1_5 Python3.x入门 P5 【基础】不可变序列(元组tuple、字符串str)
- 六|6.1_1 Python3.x入门 P1 【基础】基础语法、注释、标识符、变量、数据类型、键盘录入input