After upgrading from SpringBoot 2.4.x to SpringBoot 2.5.0, I noticed that all the "jvm_" metrics are missing from the "/actuator/prometheus" output. Other metrics like "tomcat_", "hikari_*" and my custom ones were still present.

In https://stackoverflow.com/questions/57607445/spring-actuator-jvm-metrics-not-showing-when-globalmethodsecurity-is-enabled it was suggested that the problem might be cause by enabling "@EnableGlobalMethodSecurity" which I happen to use in this project.

The below quoted workaround did indeed fix the problem for me:

@Configuration
public class ActuatorMetricsConfig {

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

}

Comment From: snicoll

Thanks for the report. I can't say for sure as you haven't shared a sample but there was a regression in that area that was fixed in 2.5.1-SNAPSHOT. Can you please test with the snapshot? If that still doesn't work, we'll need a small sample that reproduces the problem (as a zip attached to this issue or a link to a GitHub repository).

Comment From: silver-mx

I am using the /metrics actuator endpoint and I can also see that the following metrics are not present in 2.5.0 and were in 2.4.6.

NOTE: I am using @EnableGlobalMethodSecurity as well.

"jvm.buffer.count",
"jvm.buffer.memory.used",
"jvm.buffer.total.capacity",
"jvm.classes.loaded",
"jvm.classes.unloaded",
"jvm.gc.live.data.size",
"jvm.gc.max.data.size",
"jvm.gc.memory.allocated",
"jvm.gc.memory.promoted",
"jvm.gc.pause",
"jvm.memory.committed",
"jvm.memory.max",
"jvm.memory.used",
"jvm.threads.daemon",
"jvm.threads.live",
"jvm.threads.peak",
"jvm.threads.states",
"logback.events",
"process.cpu.usage",
"process.files.max",
"process.files.open",
"process.start.time",
"process.uptime",
"system.cpu.count",
"system.cpu.usage",
"system.load.average.1m",

I could not try with 2.5.1-SNAPSHOT as maven did not find it, in which maven public repo is that available?

Comment From: snicoll

I could not try with 2.5.1-SNAPSHOT as maven did not find it, in which maven public repo is that available?

Please explore a project on start.spring.io using 2.5.1-SNAPSHOT and it'll show you how to setup your build (repo.spring.io/snapshot).

Comment From: silver-mx

Yes, I tried 2.5.1-SNAPSHOT, and all the metrics that existed in 2.4.6 + spring.data.repository.invocations are now present in 2.5.1-SNAPSHOT. So it looks like the problem has been fixed. Thanks!

Comment From: snicoll

@silver-mx alright, another problem then. Can you please share a small sample that reproduces the problem? You can attach the zip here or share a link to a GitHub repo.

Comment From: silver-mx

Just to be sure. As I mentioned, the reported problem is fixed in the version 2.5.1-SNAPSHOTbut you still need a sample that reproduces the issue right?

Comment From: snicoll

Ah sorry, more coffee needed here! I read your feedback backwards. Thanks for confirming that 2.5.1-SNAPSHOT fixes the problem (with is more aligned with what I was expecting).

@lathspell can you please try with 2.5.1-SNAPSHOT on your project as well to make sure it isn't a separate problem?

Comment From: lathspell

I can confirm that 2.5.1-SNAPSHOT fixes the problem. I now see 48 metrics starting with "jvm" again.

Comment From: snicoll

Brilliant. Thanks for testing the snapshot @lathspell!

Closing as a duplicate of #26630