Reputation: 409
I spent some time reading Counter
of micrometer.io
. For my specific use case I need to always start the counter with a specific value which is available at start of application.
Since the application has multiple pods I want this inital value to be set and then can be incremented by any number of pods. The only method the Counter
supports is increment. I thought of using Gauge
but there are various cons since my metric is always an unbounded incremental counter with a starting set value.
Has anyone solved this use case before or can there be a workaround?
Upvotes: 1
Views: 3829
Reputation: 14943
As @Jonatan mentioned: a Gauge is what you would use in this case. You even could create a gauge that points to an instance variable that get updated.
That way you could set the instance variable to a value on startup and update it in the background to query your database. I use this technique in places where the query is too slow, so I don't want it happening during a metric scrape.
Upvotes: 0
Reputation: 6833
You can increment
a Counter
with any arbitrary value at startup but I don't recommend doing that:
Counter
will lie to you since you will not see the amount of increments but something elseCould you please tell us about your use-case, based on what you told, I think you don't need an initial value for your counter but add some sort of an instance id to your running instances (e.g.: pod name) and aggregate these (sum them) on your metrics backend.
Upvotes: 2