question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no jvm metrics gathering because of wrong order of Bean registrations

See original GitHub issue

Having plugged in spring-boot-starter-actuator and micrometer-registry-graphite into my Spring Boot 2 Application, the only metrics i get are those from Hikari Pool. No others like jvm or system ones.

After extensive debugging, i found out that the order of bean registrations might be a problem in my app. Disclaimer: I only added those 2 deps and added 3 lines of spring boot config. So no manual wiring with classes on my side.

The problem in detail seems to be that MeterRegistryPostProcessor @Bean in MetricsAutoConfiguration.class is instanciated before the GraphiteMeterRegistry @Bean in GraphiteMetricsExportAutoConfiguration.class.

The result is that the PostProcessor is not applied on the GraphiteRegistry and thus no configuration is being done on it.

Looking at the class mentioned class:

@Configuration
@AutoConfigureBefore({ CompositeMeterRegistryAutoConfiguration.class,
		SimpleMetricsExportAutoConfiguration.class })
@AutoConfigureAfter(MetricsAutoConfiguration.class)
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(GraphiteMeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.graphite", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(GraphiteProperties.class)
public class GraphiteMetricsExportAutoConfiguration {
...
}

There is a @AutoConfigureAfter annotation. What i dont get is, what does that mean, does it mean that this GraphiteMetricsExportAutoConfiguration @Configuration should be run after MetricsAutoConfiguration or vice versa?

Since i dont control any of those classes and i also dont use them programmatically, i dont know what to do on my side. I tried to replace the GraphiteMetricsExportAutoConfiguration with my own implementation but that didnt work. Perhaps i need to fork the micrometer-registry-graphit and play around with some modifiations on that, but have done yet.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
izeyecommented, Sep 4, 2018

@logemann Thanks for the sample!

ShiroFilterFactoryBean which is a BeanPostProcessor and has a dependency on DefaultWebSecurityManager will trigger early initialisation. I reworked it to prevent ShiroFilterFactoryBean from triggering early initialisation and created https://github.com/logemann/sample-micrometer-spring-boot/pull/1 against your fork.

Closing as this doesn’t seem to be a Micrometer issue.

0reactions
Wubbwubbcommented, Nov 6, 2019

I think I’ve found a possible reason for the problem.

In my application I used an autowired RestTemplateBuilder in some of my Service classes. The RestTemplateAutoConfiguration caused the trouble with the AutoConfiguration order, since the PrometheusMetricsExportAutoConfiguration was called by the RestTemplateAutoConfiguration (before MetricsAutoConfiguration).

After I removed the autowired RestTemplateBuilders the PrometheusMetricsExportAutoConfiguration has been configured after MetricsAutoConfiguration - like the annotation @AutoConfigureAfter in PrometheusMetricsExportAutoConfiguration says…

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Spring Actuator JVM metrics not showing when ...
I managed to make it work by adding this configuration: @Configuration public class ActuatorMetricsConfig { @Bean InitializingBean ...
Read more >
Micrometer: Spring Boot 2's new application metrics collector
Micrometer is a dimensional-first metrics collection facade whose aim is to allow you to time, count, and gauge your code with a vendor ......
Read more >
Gathering Metrics with Micrometer and Spring Boot Actuator
Traditionally, metrics have really been not much more than just simple key/value pairs - where the key is usually some dot-separated string ...
Read more >
Monitoring spring boot apps using micrometer metrics
With the New Relic Micrometer registry, you can now use Spring Boot ... Micrometer is a library for collecting metrics from JVM-based ...
Read more >
Spring Boot app metrics - with Prometheus and Micrometer
This is great for us, because once we have added Micrometer to our application, it will happily sit there collecting and exposing metrics....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found