Is it a CounterVec you're using?

If so, I think that v.With(labels...) should be sufficient to initialise it.

On Wednesday, 3 May 2023 at 20:52:57 UTC+1 Johny wrote:

> Yes golang. I am using promauto to auto register my metrics with the 
> default registry at the time of initialization.
>
> https://pkg.go.dev/github.com/prometheus/client...@v1.15.1/prometheus/promauto
>  
> <https://pkg.go.dev/github.com/prometheus/client_golang@v1.15.1/prometheus/promauto>
>
> Do you recall a way to force export it always with a default initial value 
> of 0? 
>
> On Wednesday, May 3, 2023 at 3:33:38 PM UTC-4 Brian Candler wrote:
>
>> Yes, you should be able to create a counter which publishes its initial 
>> value of zero. I'm fairly sure I've done this with the Golang client some 
>> time in the past. What language and client library are you using?
>>
>> You'll have to initialise the counters explicitly. If the first time the 
>> client library knows about the counter is when you increment it, then 
>> clearly it won't be able to export it until then.
>>
>> On Wednesday, 3 May 2023 at 20:19:27 UTC+1 Johny wrote:
>>
>>> I need to sum two separate counter metrics capturing request failures  
>>> to compute ratio of error requests for an alerting signal. The code 
>>> initializing and setting these counters sits in separate modules preventing 
>>> reuse of one counter.
>>>
>>> The problem is when one of the counter is never incremented after a 
>>> restart, service never exports the data point, prometheus will never get 
>>> the time series and the summation will return nothing. 
>>>
>>> Is there a way to "force" publish a counter to 0 always on service 
>>> reboot during counter initialization to avoid this problem?
>>>
>>>  (fail_count1 + fail_count2) / (total_count1 + total_count2)
>>>
>>>

-- 
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 prometheus-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/ad84a4e8-3aa4-476a-9b18-edc11ebd1ac5n%40googlegroups.com.

Reply via email to