pip install prometheus-client 1. 基于flask服务代码示例 随机返回一些数值 # -*- coding: utf-8 -*- """ @File : demo.py @Date : 2023-06-30 """ import random import prometheus_client from flask import Flask, Response from prometheus_client import Gauge from prometheus_client.core import Coll...
from prometheus_clientimportCounter,Gauge,Summary,Histogram,start_http_serverimportpsutilimporttime # 定义和注册指标 cpu_percent=Gauge('cpu_percent','CPU 使用率百分比')cpu_freq_current=Gauge('cpu_freq_current','CPU 当前频率')cpu_freq_min=Gauge('cpu_freq_min','CPU 最小频率')cpu_freq_max=Gaug...
一、常用函数 Prometheus为不同的数据提供了非常多的计算函数,其中有个小技巧就是遇到counter数据类型,在做任何操作之前,先套上一个rate()或者increase()函数。下面是一些比较常用的函数: 1、rate函数 rate() 函数是专门搭配counter数据类型使用函数,功能是取counter在这个时间段中平均每秒的增量。例如:获取eth0网卡1m...
label1 ='111'label2 ='222'label3 ='333'data1 ='444'# 调用Gauge数据类型,把采集的数据放入到设定的example_Gexample_G.labels(label1,label2,label3).set(data1)# return需放在函数下最外层,否则返回的数据有缺失returnprometheus_client.generate_latest(REGISTRY)# 用uvicorn调用接口,启用端口为9330if__...
from prometheus_client import CollectorRegistry, Gauge def prometheus_temperature(num): registry = CollectorRegistry() g = Gauge("red_hat_temp", "Temperature at Red Hat HQ", registry=registry) g.set(num) return registry 最后,我们需要以某种方式将它连接到 Prometheus。这有点依赖 Prometheus 的网络拓扑...
Python prometheus-client 安装 pip install prometheus-client Python封装 # encoding: utf-8fromprometheus_clientimportCounter, Gauge, Summaryfromprometheus_client.coreimportCollectorRegistryfromprometheus_client.expositionimportchoose_encoderclassMonitor:def__init__(self):# 注册收集器&最大耗时mapself.collector_reg...
prometheus-client 0.11.0 代码实现 代码语言:javascript 复制 !/usr/bin/env python-*-coding:utf-8-*-from prometheus_clientimportCollectorRegistry,Gauge,push_to_gatewayif__name__=='__main__':registry=CollectorRegistry()labels=['req_status','req_method','req_url']g_one=Gauge('requests_total',...
pip install prometheus-client AI代码助手复制代码 Python封装 # encoding: utf-8fromprometheus_clientimportCounter, Gauge, Summaryfromprometheus_client.coreimportCollectorRegistryfromprometheus_client.expositionimportchoose_encoderclassMonitor:def__init__(self):# 注册收集器&最大耗时mapself.collector_registry = ...
Gauge也可以从回调中获取其值: d=Gauge('data_objects','Number of objects')my_dict={}d.set_function(lambda:len(my_dict)) 摘要 摘要跟踪事件的大小和数量。 fromprometheus_clientimportSummary s=Summary('request_latency_seconds','Description of summary')s.observe(4.7)# Observe4.7(secondsinthiscase...
from prometheus_client import CollectorRegistry, Gauge def prometheus_temperature(num): registry = CollectorRegistry() g = Gauge("red_hat_temp", "Temperature at Red Hat HQ", registry=registry) g.set(num) return registry 最后,我们需要以某种方式将它连接到 Prometheus。这有点依赖 Prometheus 的网络拓扑...