添加以下课程时,我无法访问/metrics
端点-
ExporterRegister.class
public class ExporterRegister {
private List<Collector> collectors;
public ExporterRegister(List<Collector> collectors) {
for (Collector collector : collectors) {
collector.register();
}
this.collectors = collectors;
}
public List<Collector> getCollectors() {
return collectors;
}
}
CollectorRegistry.class
@Configuration
@ConditionalOnClass(CollectorRegistry.class)
public class MetricController {
private static final CollectorRegistry metricRegistry = CollectorRegistry.defaultRegistry;
@Bean
ServletRegistrationBean registerPrometheusExporterServlet() {
return new ServletRegistrationBean(new MetricsServlet(metricRegistry), new String[]{"/metrics"});
}
@Bean
ExporterRegister exporterRegister() {
List<Collector> collectors = new ArrayList<>();
collectors.add(new StandardExports());
collectors.add(new MemoryPoolsExports());
collectors.add(new GarbageCollectorExports());
collectors.add(new ThreadExports());
ExporterRegister register = new ExporterRegister(collectors);
return register;
}
}
我正在使用Spring Boot 2.1.4版本,以下是我在pom.xml中使用的Prometheus依赖项
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.6.0</version>
</dependency>
我的应用程序属性-
server.servlet.context-path=/something
server.error.whitelabel.enabled = true
#overriding old spring beans with newer version
spring.main.allow-bean-definition-overriding=true
#enable console logs
logging.level.org.apache.http.wire=DEBUG
#Metrics related config
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.beans.enabled=false
management.endpoint.info.enabled=true
management.endpoints.enabled-by-default=true
management.server.port=8081
当我尝试访问此URL时-http://localhost:8080/something/metrics
我找不到404
答案 0 :(得分:0)
默认情况下,所有执行器端点都映射在/actuator
下。使用/something
的上下文路径,这意味着指标端点将在/something/actuator/metrics
可用。