Python查询Prometheus API #!/bin/python # -*- coding: utf-8 -*- import pandas as pd import requests, time, re def getcolumn(status, x): if float(status) < 80: return "正常" # elif float(status) < 2: # return "异常"
我们要想抓取Prometheus的数据,一般想到的就是requests请求,爬虫的方式来抓取,这是可行的,当然,还有一个第三方库直接封装好了,直接用就行,代码也比较少,源码点进去就能看明白,这个库叫prometheus-api-client,github地址和pypi地址 1、下载 python -m pip install prometheus-api-client 2、使用 连接Prometheus 使用Pr...
python 对 prometheus API 的封装 PromQL 是 Prometheus 提供的一个函数式的表达式语言,可以使用户实时地查找和聚合时间序列数据。表达式计算结果可以在图表中展示,也可以在 Prometheus表达式浏览器中以表格形式展示,或者作为数据源,以 HTTP API 的方式提供给外部系统使用。PromQL 虽然以 QL 结尾,但是它不是类似 SQL 的...
让我们来写一个简单的 Python 脚本,通过 Prometheus API 获取数据。我们将从 Prometheus 服务器查询 CPU 使用率。 importrequestsdefget_prometheus_data(query,prometheus_url='http://localhost:9090'):url=f"{prometheus_url}/api/v1/query"params={'query':query}response=requests.get(url,params=params)ifre...
$python test_api.py服务器 192.168.214.108的node_load5值为 0.01 结语 本文仅展示了 Prometheus API 的简单应用,更多的接口使用可参考官方文献:https://prometheus.io/docs/prometheus/latest/querying/api/。 来源:本文转自公众号 DevOps 进阶之路, 点击查看原文 。
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=...
工作中需要通过CPU、内存生成资源利用率报表,可以通过Prometheus的API写一个Python脚本。 可通过API获取数据,然后再进行数据排序、过滤、运算、聚合,最后写入Mysql数据库。 CPU峰值计算 取最近一周CPU数值,再排序取最高的值。 def get_cpu_peak(self):
基于Prometheus的监控告警系统的Python开发(二) 书接上回 https://cloud.tencent.com/developer/article/2195953 之前设计的有点问题,最近心血来潮有捡起来继续写。简单优化一版 1、将所有的规则组的webhook统一为一个api接口,全部在django里面进行告警的路由...
查询API¶ 查询API位于/api/v1/下, Targets(监控目标)¶ 请求地址 GET /api/v1/targets 请求案例 [root@linux-node1 ~]# curl -s -u admin:password http://192.168.56.11:9090/api/v1/targets | python -m json.tool { "data": { "activeTargets": [ { "discoveredLabels": { "__address_...
python-prometheus-api-client 介绍 A Python wrapper for the Prometheus http api and some tools for metrics processing. 软件架构 软件架构说明 安装教程 xxxx xxxx xxxx 使用说明 xxxx xxxx xxxx 参与贡献 Fork 本仓库 新建Feat_xxx 分支 提交代码 新建Pull Request 特技 使用Readme_XXX.md 来支持不同的语言...