How to update counter value in Pushgateway?

462 Views Asked by At

I don't understand how can I update Counter type metrics in pushgateway. For example

registry = CollectorRegistry()
Counter('rows', 'rows info', registry=registry).inc(0.555)
push_to_gateway(host,
                job='batch_job',
                registry=registry,
                timeout=10)

And I get after first push enter image description here

Then I push again but value 0.555 don't change. I want to get 1.11 in this case (want to accumulate values in this metrics). Try to use push_add_to_gateway, but result is the same.

1

There are 1 best solutions below

0
On

There are 2 things:

  1. when you do a "push_to_gateway" you are not incrementing a value but replacing it.
    This makes counters a bit difficult to set up understand sometimes. In your case if you want to increment the value you need to keep track of what you already had pushed before. For example:
registry = CollectorRegistry()
c = Counter('rows', 'rows info', registry=registry)
c.inc(0.555)
push_to_gateway(host,
                job='batch_job',
                registry=registry,
                timeout=10)
# ....
c.inc(0.555)
push_to_gateway(host,
                job='batch_job',
                registry=registry,
                timeout=10)
  1. When you query the data, you need to use increase function to see how much that value was increased during that time, this function will detect resets which would happen if you run 2 times the same function in different applications.