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.

Metrics not appearing in prometheus endpoint

See original GitHub issue

We have a funny behavior that started appearing with RC8, if we go back to RC7 it disappears: The common Spring metrics do not appear in the Prometheus endpoint like jvm_memory_committed_bytes, system_cpu_count, etc.

Even more funny, the behavior is only happening in one of two of our projects, even though most dependencies are the same - we use Spring Boot 1.5.10, Spring Cloud Edgware.SR2, Micrometer 1.0.2.

The problem seems to lie in the order the auto configurations are applied:

In the project that has no issues, io.micrometer.spring.autoconfigure.MetricsAutoConfiguration#meterRegistryPostProcessor is executed first, then io.micrometer.spring.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration#prometheusMeterRegistry. Therefore the postprocessor is instantiated first and finally registers all Spring metrics.

In the project that is not working, the order is swapped and the postprocessor does not get invoked with the PrometheusMeterRegistry bean.

This is funny, as PrometheusMetricsExportAutoConfiguration is annotated with @AutoConfigureAfter({MetricsAutoConfiguration.class}).

The documentation on @AutoConfigureAfter is non existent but if I understand the kind of only resource in the internet correctly (https://stackoverflow.com/questions/42284478/autoconfigureafter-not-working-as-desired) it is just used to create the dependency graph but does not necessarily influence the order of creation? In that case, adding an (unused) parameter with type MeterRegistryPostProcessor to the factory method io.micrometer.spring.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration#prometheusMeterRegistry might not be too elegant but already solve the issue?

Thanks Marco

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

18reactions
golonzovskycommented, Aug 8, 2018

We had similar issue on our side. In our case we have BeanPostProcessor, which replaces RestTemplate of oauth2 RemoteTokenServices (in order to enable timeouts and zipkin tracing), so all JVM metrics were missing.

In our case we used following hack similar to one from @marcoschulte (as MeterRegistryPostProcessor is package private now)

@Bean
InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, PrometheusMeterRegistry registry) {
	return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
}

We hope this would go away in our case with support of server-oauth2 in next spring security, as this hack is quite fragile…

Dependency graph looked like this: OurBeanPostProcessor -> restTemplateBuilder -> metricsRestTemplateCustomizer -> prometheusMeterRegistry which caused prometheusMeterRegistry to be created too early when most of MeterBinders are not yet there…

3reactions
marcoschultecommented, Mar 23, 2018

Btw. for anyone else having this issue, this fixes it for now:

@Configuration
public class FixPrometheusMetrics {
    public FixPrometheusMetrics(MeterRegistryPostProcessor postProcessor, PrometheusMeterRegistry registry) {
        postProcessor.postProcessAfterInitialization(registry, "");
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Metrics not appearing at prometheus endpoint when I'm using ...
When I run ./prometheus --config.file=prometheus.yml , I can access the endpoint http://localhost:9090/metrics and also http://localhost:9090/ ...
Read more >
Troubleshoot Prometheus | Open Service Mesh
Metrics are not showing up in Prometheus. If Prometheus is found not to be scraping metrics for any Pods, perform the following steps...
Read more >
Prometheus - IBM
The Instana prometheus sensor doesn't require a Prometheus server. The sensor captures metrics directly from the endpoints that are exposed by the monitored ......
Read more >
Adding custom metrics to Spring Boot Micrometer Prometheus ...
If you have problems with @Timed metrics not showing up, try adding a Configuration object that returns a TimedAspect like this. Or you...
Read more >
Troubleshooting Managed Service for Prometheus
If you query the up metric and do not see any results, then the problem is on the ingestion side. For information on...
Read more >

github_iconTop Related Medium Post

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