我想通过PUSH_TO_Gateway函数将指标推送到我的普罗米修斯服务器,但我在普罗米修斯服务器上设置了基本身份验证. 如何在Push_to_Gateway函数中发送用户名和密码?

推荐答案

这是官方 case ,你可以试着用它来测试

这款车 https://pypi.org/project/prometheus-client/

pip install prometheus-client

from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
from prometheus_client.exposition import basic_auth_handler

def my_auth_handler(url, method, timeout, headers, data):
    username = 'foobar'
    password = 'secret123'
    return basic_auth_handler(url, method, timeout, headers, data, username, password)
registry = CollectorRegistry()
g = Gauge('job_last_success_unixtime', 'Last time a batch job successfully finished', registry=registry)
g.set_to_current_time()
push_to_gateway('localhost:9091', job='batchA', registry=registry, handler=my_auth_handler)

Python相关问答推荐

Python plt.text中重叠,包adjust_text不起作用,如何修复?

Chatgpt API不断返回错误:404未能从API获取响应

当密钥是复合且唯一时,Pandas合并抱怨标签不唯一

理解Python的二分库:澄清bisect_left的使用

使用新的类型语法正确注释ParamSecdecorator (3.12)

追溯(最近最后一次调用):文件C:\Users\Diplom/PycharmProject\Yolo01\Roboflow-4.py,第4行,在模块导入roboflow中

可变参数数量的重载类型(args或kwargs)

Polars:用氨纶的其他部分替换氨纶的部分

Scrapy和Great Expectations(great_expectations)—不合作

实现神经网络代码时的TypeError

从Windows Python脚本在WSL上运行Linux应用程序

如何在TensorFlow中分类多个类

无论输入分辨率如何,稳定扩散管道始终输出512 * 512张图像

在极中解析带有数字和SI前缀的字符串

mdates定位器在图表中显示不存在的时间间隔

为什么dict. items()可以快速查找?

删除Dataframe中的第一个空白行并重新索引列

pytest、xdist和共享生成的文件依赖项

在matplotlib中重叠极 map 以创建径向龙卷风图

按列表分组到新列中