Search code examples
javaspringspring-bootspring-jmxmicrometer

How do i use micrometer with jmx in spring boot app?


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.


Solution

  • 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>