我想通过push_to_gateway函数将指标推送到Prometheus服务器,但我在Prometheus服务器上设置了基本身份验证。如何在push_to_gateway函数中发送用户名和密码?
camsedfj1#
这是官方案例,你可以试着用它来测试此型号https://pypi.org/project/prometheus-client/pip install prometheus-client
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)
1条答案
按热度按时间camsedfj1#
这是官方案例,你可以试着用它来测试
此型号
https://pypi.org/project/prometheus-client/
pip install prometheus-client