5

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;
                }
            }
        }
Anky
  • 111
  • 15

1 Answers1

0

I could work this out via Prometheus queries where I needed to count from zero, but the metrics were created with one after the first scrape.

increase(sum(last_over_time(my_custom_counter_total[$__range]) or vector(0))[$__range:1m])
João Pedro Schmitt
  • 1,046
  • 1
  • 11
  • 25