prix
prix

Reputation: 101

Micrometer publish to JMX in non-SpringBoot-Project

It seems like there is a lot of magic going on in Micrometer and SpringBoot to publish to the chosen monitoring system.

Is it possible to publish the information I gather with Micrometer to JMX in a non-SpringBoot application?

I added the dependency

implementation 'io.micrometer:micrometer-registry-jmx:latest.release'

and I added a Timer like that

Timer timer =
      Timer.builder("name")
          .publishPercentiles(0, 0.5, 0.75, 0.95)
          .register(Metrics.globalRegistry);

but now I need to publish that data to JMX to be able to see that data in the JConsole. I searched the internet but as I am pretty new to Micrometer and JMX, I am not able to find anything that helps me solve that problem yet.

Upvotes: 0

Views: 1153

Answers (1)

Jonatan Ivanov
Jonatan Ivanov

Reputation: 6873

I'm not sure what magic are you referring to, Spring Boot will auto-configure the MeterRegistry instances for you.

If you want to use the JmxMeterRegistry, you need to create an instance of it, see: docs and samples.

Then you can use it:

MeterRegistry registry = new JmxMeterRegistry(...);
Timer timer = Timer.builder("test").register(registry);

If you don't want to inject your MeterRegistry everywhere, you can use the global registry, see the docs:

MeterRegistry registry = new JmxMeterRegistry(...);
Metrics.addRegistry(registry);

Though recommend injecting your MeterRegistry especially if you are using any dependency injection solution.

Upvotes: 1

Related Questions