python获取tidb prometheus监控数据

# -*- coding:utf-8 -*- #

import requests  
import time

‘‘‘
采样范围太大就会提示
{"status":"error","errorType":"execution",
"error":"query processing would load too many samples into memory in query execution"}
‘‘‘

check_address = {
                "test1":"http://192.168.1.1:9090/",
                "test2":"http://192.168.1.2:9090/",
                "test3":"http://192.168.1.3:9090/"
                }
                
                
check_target= {"tikv_disk_used":"sum(tikv_engine_size_bytes{} ) by (instance) /1000/1000/1000",
               "tikv_mem":"process_resident_memory_bytes{job=‘tikv‘}/1024/1024/1024",
               "region_nums":"pd_cluster_status{type=‘region_count‘}",
               "tikv_cpu_used":"sum(rate(tikv_thread_cpu_seconds_total{job=‘tikv‘}[30m])) by (instance) * 100"}

for project,address in check_address.items():
    print("---------------项目{}---------------".format(project))
              
    for key,expr in check_target.items():
        print("[{}]".format(key))
        url = address + ‘/api/v1/query?query=‘ + expr
        response = requests.get(url,params={‘query‘:‘expr‘})
        
        try:
            for i in response.json()[‘data‘][‘result‘]:
                check_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(i[‘value‘][0]))
                print("实例{}\t采集时间{}\t当前数值{}".format(i[‘metric‘][‘instance‘],check_time,i[‘value‘][1]))
        except Exception as e:
            print(‘Error:‘, e)
            continue

  

python获取tidb prometheus监控数据

上一篇:Oracle 11.2.0.4 TNS 监听器远程中毒漏洞(CVE-2012-1675)修复方案


下一篇:sqlserver怎样查询出当天,本周,本月的数据???