I am working on a use case in which new time series gets created whenever metrics are pushed. I am using counter for my metrics. And I am using sum(increase(metric_name{_namespace_="elvis", Label1=~"d1", Label2=~"d2", Label3=~"d3"}[2m])) by (Label1, Label2, Label3)
But my counters are getting initialized to 1 and not 0 because of which when i use the above query, I am not able to see the jump in counter from 0 to 1. I tried to initialize my counters while registering it as shown below but it doesn't help. Any help would be greatly appreciated
SimpleCollector counter = metricsMap.get(metricName);
double cntrValue = 0d;
if (counter == null) {
synchronized (metricsMap) {
counter = metricsMap.get(metricName);
if (counter == null) {
counter = Counter.build()
.name(decorateMetricsName(metricName))
.help(decorateMetricsName(metricName) + " counter")
.register();
metricsMap.put(metricName, counter);
cntrValue = ((Counter) counter.labels(getLabelValues(labels))).get();
logger.info( "Manifested Time Series with value");
logger.info( "Registered " + metricName);
} else {
return (Counter)counter;
}
}
}