Prometheus push gateway how to increment message requests

569 Views Asked by At

I have a use case where we need to increment the number of requests received on a Nuclio serverless service. Pod is recreated each time the service is invoked. Following the examples from the Prometheus-client library, I am not able to increment the request number using Counter()or Gauge() Object and inc() method, here is the code I tried.

registry = CollectorRegistry()
c = Counter('my_requests', 'HTTP Failures', ['method', 'endpoint'],registry=registry) 
c.labels(method='get', endpoint='/').inc()
c.labels(method='post', endpoint='/submit').inc()
pushadd_to_gateway('localhost:8082', job='countJob', registry=registry)

I tried both push_to_gateway and pushadd_to_gateway both resulted the counter value for my_requests remain 1.

Question - by creating the Counter object each time does it resets the increment value back to 0, if so how do we go about it for ephomeral jobs ? Any code example would be helpful.

0

There are 0 best solutions below