Hello All,
I am facing similar issue when using counters with labels. I have counters
to track some events that only increases over time, like no of users
submitted a form. These forms belongs to a year.
I want to track no of forms submitted for year, say 2019/2020/2021 etc. I
am using labeled counter to track this.
I am using increase function to track no of forms submitted for particular
year, in a given time range like *increase( forms_submitted { year=2019 } [
2h ] ).*
Below is the observation
First If we query prometheus, they query result is empty.
On first inc(), it is incremented to 0. after second inc() the sum is 1.
As a solution, I have initialised the counter to zero (by doing inc(0) )
for all labels in the application code as I know the labels in advance.
If we can initialise the counter at the time of building it it could have
solve the above issue.
I know that counter can not have set() method.
Internally for labeled counters, there are independent counters (children).
What if we have initialise() method in Builder, which initialises the value
of the counter for all labels while creating labeled counter ?
On Wednesday, July 8, 2020 at 5:08:31 PM UTC+5:30 Julien Pivotto wrote:
> You did not pass values to labels (). You must give it the label value.
>
> Le mer. 8 juil. 2020 à 13:35, Nipuni Chandimali <[email protected]> a
> écrit :
>
>> Hi Julien,
>>
>> Thank you very much for the response. I used the following code segment.
>>
>> I register the Counter like this
>> static final Counter TOTAL_REQUESTS_RECEIVED = Counter.build
>> (MetricConstants.PROXY_REQUEST_COUNT_TOTAL,"Total no.of requests").
>> labelNames("test").register();
>>
>> and use the following method in the server shutdown method.
>> TOTAL_REQUESTS_RECEIVED.labels();
>>
>> But still the previous counter values are not set to 0.
>>
>> Please help me to solve this.
>>
>> Thanks.
>>
>>
>> On Wed, 8 Jul 2020 at 02:36, Julien Pivotto <[email protected]>
>> wrote:
>>
>>> On 07 Jul 11:51, Nipuni wrote:
>>> > I want to set Prometheus Counter value to 0 when the server restarts
>>> in a
>>> > manner similar to,
>>> >
>>> > * private static final Gauge SERVER_UP =
>>> Gauge.build(MetricConstants.SERVER_UP, "Server
>>> status").labelNames(labels).register();*
>>> >
>>> > * Gauge gauge = (Gauge) map.get(SERVER_UP);*
>>> > * gauge.labels(serviceName, serviceType).set(0);*
>>> >
>>> >
>>> > How can this be done with Counters ?
>>>
>>> Just call the .labels() function without .inc()
>>>
>>>
>>> >
>>> > --
>>> > 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/f3d920aa-31a7-4446-ab2d-c7b5d3fddd50o%40googlegroups.com
>>> .
>>>
>>>
>>> --
>>> Julien Pivotto
>>> @roidelapluie
>>>
>> --
>> 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/CAKHONj3kD4Ps-hjJ8%3DKaExodeFepk51bDDmQ9T9mCY7AmPt-SQ%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/prometheus-users/CAKHONj3kD4Ps-hjJ8%3DKaExodeFepk51bDDmQ9T9mCY7AmPt-SQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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/573cb950-45ee-4657-b5c6-a8126ebc12f0n%40googlegroups.com.