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