4

I am fairly new to micrometer metric and having some issues with basic setup in my spring boot application.

Code:

MeterRegistry registry = new SimpleMeterRegistry();
Timer timer = registry.timer("app.event", "type","ping");
timer.record(System.currentTimeMillis() - date.getTime(),TimeUnit.MILLISECONDS);

I tried looking for a bean with the name of ping in jmx using jconsole, but I am not able to find it. I believe there is something basic I am missing here, but not sure of the real cause. I tried following the micrometer documentation as well, but it seems to explain different functions of micrometer without much sample examples. I would really appreciate any help on this.

Johnny Lim
  • 5,623
  • 8
  • 38
  • 53
Ankit Kumar
  • 43
  • 1
  • 4

2 Answers2

7

Perhaps you haven't included the jmx exporter?

From the documentation:

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-jmx</artifactId>
  <version>${micrometer.version}</version>
</dependency>
ninj
  • 1,529
  • 10
  • 10
2

You need to use the auto-configured MeterRegistry. So you should inject MeterRegistry into any component you want to create meter(s) rather than creating your own one there. Or you can create your own one as a bean if necessary.

I created a sample demonstrating how to do it. Note that it's on the so-51940816 branch, not the master.

Johnny Lim
  • 5,623
  • 8
  • 38
  • 53