Thanks Brian. I was able to use <CounterVec>.withLabels(...).Add(0) in the 
beginning to export the 0 value.

On Wednesday, May 3, 2023 at 4:55:03 PM UTC-4 Brian Candler wrote:

> Confirmed. Take the "Basic Example" from here:
>
> https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#hdr-A_Basic_Example
>
> Remove the .Inc() from the "m.hdFailures.With" line
>
> $ curl -fsS localhost:8080/metrics | grep hd_errors
> # HELP hd_errors_total Number of hard-disk errors.
> # TYPE hd_errors_total counter
> hd_errors_total{device="/dev/sda"} 0
>
> On Wednesday, 3 May 2023 at 21:51:53 UTC+1 Brian Candler wrote:
>
>> 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/[email protected]/prometheus/promauto
>>>  
>>> <https://pkg.go.dev/github.com/prometheus/[email protected]/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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/55e76e23-6a34-4aca-b81b-90a1366fb2cen%40googlegroups.com.

Reply via email to