0

I have a Spring Boot Application which I'm migrating to Micrometer right now.

What I'd like to achieve is, to count the invocation over time for specific objects.

Let's assume I have a function which creates cars of certain Brands. Then I'd like to measure how many Ford, Skoda, VW and so on I created in the past minute. Especially, if there was no Skoda created between now()-1 and now() then the metric should return 0.

The docs state that I shouldn't use counter, since the number of created cars can grow indefinitely while running the App. Also a Timer isn't really fitting since I'd only start the timer before Constructor invocation and after that.

I tried a gauge, but also this only gives me absolute numbers:

Arrays.stream(brand).forEach(brand -> metricNames.stream().forEach(name -> {
      String id = METRIC_PREFIX + METRIC_SEPARATOR + brand + name;
      AtomicInteger summary = Metrics.gauge(id, new AtomicInteger(0));
      summary.getAndIncrement();
    }));

In dropwizard there were Meters, but what is the equivalent in Micrometer?

questionaire
  • 2,475
  • 2
  • 14
  • 28

1 Answers1

0

You need a counter:

    MeterRegistry metrics...

    private final Counter nikeBrandCounter = metrics.counter("brands", "brand", "Nike");

    Arrays.stream(brand).forEach(brand -> metricNames.stream().forEach(name -> {
        if(name == "Nike") {
            nikeBrandCounter.increment();
        }
    }));
Sherms
  • 1,567
  • 1
  • 15
  • 31