Ankit Kumar
Ankit Kumar

Reputation: 53

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.

Upvotes: 5

Views: 10321

Answers (2)

Johnny Lim
Johnny Lim

Reputation: 5833

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.

Upvotes: 2

ninj
ninj

Reputation: 1549

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>

Upvotes: 7

Related Questions