claws / aioprometheus

A Prometheus Python client library for asyncio-based applications
174 stars 21 forks source link

How to push the same name metrics in the same batch #92

Closed simbafl closed 11 months ago

simbafl commented 12 months ago

Add() will replace only any metrics with the same metric name and labels within a pushed group. Push() completely removes all previous metrics in a pushed group and then only adds the newly pushed ones.

I want to push the same name metrics in the same batch, and the error is as follows: raise ValueError(f"A collector for {collector.name} is already registered")

So, how should I achieve it?

simbafl commented 11 months ago

resolved

mfournioux commented 5 months ago

Hello @simbafl,

could you please share how did you solve this issue?

Many thanks

msaysell commented 1 month ago

I managed to get around this by creating the metric in a cached function and calling that to access it

from functools import cache

@cache
def get_gauge():
    return Gauge("my_gauge", "Gauge", {})