在基于Springboot的应用程序中,我无法使用@EnableAutoConfiguration,因此必须将所有配置手动添加到@Import批注。我知道如何启用通用端点/actuator和其他一些诸如/actuator/health/actuator/env的示例(下面的示例)。但是,即使我尝试了数千种选项,也无法使metrics工作(使用@EnableAutoConfiguration可以工作)。
我的配置如下:

@SpringBootConfiguration
@ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
@Import({
        ServletWebServerFactoryAutoConfiguration.class,
        DispatcherServletAutoConfiguration.class,
        WebMvcAutoConfiguration.class,

        ManagementContextAutoConfiguration.class,
        EndpointAutoConfiguration.class,
        WebEndpointAutoConfiguration.class,

        HealthIndicatorAutoConfiguration.class,
        HealthEndpointAutoConfiguration.class,

        EnvironmentEndpointAutoConfiguration.class,

        //---------- configs metrics related:
        MetricsAutoConfiguration.class,
        CompositeMeterRegistryAutoConfiguration.class,
        JvmMetricsAutoConfiguration.class,
        MetricsEndpointAutoConfiguration.class,
        SystemMetricsAutoConfiguration.class,
        SimpleMetricsExportAutoConfiguration.class,
        WebMvcMetricsAutoConfiguration.class
}
)
public class Application {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
    }

}


使用这样的配置,即使我可以在metrics页面上看到/actuator端点:
actuator main page

如果我去那里,它显示为空集合:
no metrics

并且它应该包含系统和jvm指标(以及第一次http调用后的http端点指标)。
知道要启用Spring Actuator指标应该做什么吗?

最佳答案

我找到了一个解决方案,指标导入顺序不正确,顺序应如下:

        MetricsAutoConfiguration.class,
        SimpleMetricsExportAutoConfiguration.class,
        CompositeMeterRegistryAutoConfiguration.class,
        JvmMetricsAutoConfiguration.class,
        MetricsEndpointAutoConfiguration.class,
        SystemMetricsAutoConfiguration.class,
        WebMvcMetricsAutoConfiguration.class

09-25 20:44