I need to add metrics and then change current values of those metrics. This my script on Python3 for add 3 metrics
add.py
from prometheus_client.exposition import basic_auth_handler
r = 10
def my_auth_handler(url, method, timeout, headers, data):
username = 'admin'
password = 'secret'
return basic_auth_handler(url, method, timeout, headers, data, username, password)
registry = CollectorRegistry()
g = Gauge('test_test', 'Random gauge', ['user_status', 'status', 'country', 'state', 'city'], registry=registry)
g.labels('1', 'Rejected', 'Canada', 'AB', 'Albany').set(r)
g.labels('1', 'Suspect', 'Canada', 'AB', 'Albany').set(r)
g.labels('1', 'Trusted', 'Canada', 'AB', 'Albany').set(r)
g.labels('0', 'Trusted', 'USA', 'AB', 'Albany').set(r)
push_to_gateway('localhost:9091', job='test', registry=registry, handler=my_auth_handler)
Then I want to change value for one metric
update.py
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
from prometheus_client.exposition import basic_auth_handler
r = 10
def my_auth_handler(url, method, timeout, headers, data):
username = 'admin'
password = 'secret'
return basic_auth_handler(url, method, timeout, headers, data, username, password)
registry = CollectorRegistry()
g = Gauge('test_test', 'Random gauge', ['user_status', 'status', 'country', 'state', 'city'], registry=registry)
g.labels('1', 'Rejected', 'Canada', 'AB', 'Albany').set(r)
g.labels('1', 'Rejected', 'Canada', 'AB', 'Albany').dec()
push_to_gateway('localhost:9091', job='test', registry=registry, handler=my_auth_handler)
All works, but when all metrics are removed and I see just one, which I updated.
How I can change values of metrics, and leave all another metrics?