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

2

5

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.

Kmeson answered 21/8, 2018 at 2:34 Comment(0)
T
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>
Threadbare answered 22/8, 2018 at 22:25 Comment(0)
Z
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.

Zumwalt answered 24/8, 2018 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.