Hi folks, any ideas on this issue I am facing with custom collectors using 
the Python client?

Thanks,
Cory

On Saturday, June 20, 2020 at 10:48:43 AM UTC-5, Cory Robinson wrote:
>
> Hi,
>
> When implementing a simple custom collector with the python client, 
> refreshing the browser will generate 2 successive collections. 
> This tends to cause "duplicate" unneeded successive, say, REST API calls 
> for example,  when collecting metrics from REST API endpoints real-world 
> scenarios.
> How can this be avoided?
>
> Here is some sample case below that exhibits this behavior...
>
> import time
> from prometheus_client import start_http_server
> from prometheus_client.core import
>  GaugeMetricFamily, CounterMetricFamily, REGISTRY
>
> class CustomCollector(object):
>     def collect(self):
>         c = GaugeMetricFamily('my_gauge', 'Help text', labels=['foo'])
>         c.add_metric(['bar'], 1.7)
>         print("{}, {}".format(time.time(), c))
>         yield c
>     
>     def describe(self):
>         return []
>
> if __name__ == '__main__':
>     start_http_server(8000)
>     REGISTRY.register(CustomCollector())
>     while True:
>         time.sleep(1)
>
> Console output at webpage refresh on localhost:8000:
> > python test.py
> 1592667742.5491908, Metric(my_gauge, Help text, gauge, , 
> [Sample(name='my_gauge', labels={'foo': 'bar'}, value=1.7, timestamp=None, 
> exemplar=None)])
> 1592667742.6191902, Metric(my_gauge, Help text, gauge, , 
> [Sample(name='my_gauge', labels={'foo': 'bar'}, value=1.7, timestamp=None, 
> exemplar=None)])
>
> Notice the times come in very quick succession. When collecting real 
> metrics from a REST API endpoint, the metrics displayed on the webpage will 
> always be the first metric, not the 2nd succession.
>
> Thanks,
> Cory
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/8f84749d-492c-47c9-87f7-e7cdeb1bff33o%40googlegroups.com.

Reply via email to