如何更改普罗米修斯指标的端点

How to change the endpoint of prometheus metrics

我正在尝试将 spring-boot 服务的一些指标公开给普罗米修斯。 不幸的是,spring-boot 执行器和 prometheus 简单客户端都通过 /metrics 端点公开了它们的指标。

如何更改简单客户端的端点?

谢谢

对于您在设置 servlet 时指定端点的 java 客户端,请参见 https://github.com/RobustPerception/java_examples/blob/master/java_simple/src/main/java/io/robustperception/java_examples/JavaSimple.java#L39 示例。您可以将端点更改为您喜欢的任何内容。

您可以更改 spring-boot actuator 的端点并将 /metrics 留给 Prometheus。

将以下配置添加到您的 application.properties:

endpoints.metrics.id=springmetrics
endpoints.metrics.sensitive=false
endpoints.metrics.enabled=true

您将有一个新端点 /springmetics 用于 spring 执行器和 /metrics 用于 Prometheus。

您可能想看看 Prometheus Java Simpleclient Spring Boot Metric 它在 /prometheus 端点公开了 prometheus 指标。

Github 项目:https://github.com/prometheus/client_java/tree/master/simpleclient_spring_boot

Maven 神器:https://mvnrepository.com/artifact/io.prometheus/simpleclient_spring_boot

在你的 pom.xml 上:

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_spring_boot</artifactId>
    <version>0.0.17</version>
</dependency>

在你的springboot配置中class:

@Configuration
public class Configuration {

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        DefaultExports.initialize();
        return new ServletRegistrationBean(new MetricsServlet(), "/prometheus");
    }

    @Bean
    public SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> publicMetrics) {
        SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(
            publicMetrics);
        springBootMetricsCollector.register();
        return springBootMetricsCollector;
    }

您是否尝试在 application.properties 文件中设置这些属性:

management.endpoints.web.path-mapping.prometheus=
management.endpoints.web.base-path=