【问题标题】:Prometheus metrics - not foundPrometheus 指标 - 未找到
【发布时间】:2018-03-28 08:53:38
【问题描述】:

我有 Spring Boot 应用程序,我正在使用 vertx。 我想监控服务和 jvm,为此我选择了 Prometheus。

这是我的 MonitoringConfig 类:

@Configuration
public class MonitoringConfig {

    @Bean
    SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> publicMetrics) {

        SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(publicMetrics);
        springBootMetricsCollector.register();

        return springBootMetricsCollector;
    }

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

}

这是我的依赖项:

<dependency>
            <groupId>com.moelholm</groupId>
            <artifactId>prometheus-spring-boot-starter</artifactId>
            <version>1.0.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient -->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient</artifactId>
            <version>0.0.25</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_hotspot -->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_hotspot</artifactId>
            <version>0.0.25</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_spring_boot -->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_spring_boot</artifactId>
            <version>0.0.25</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_servlet -->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_servlet</artifactId>
            <version>0.0.25</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.hateoas</groupId>
            <artifactId>spring-hateoas</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

它在应用程序中没有显示错误,但是当我尝试访问 http://localhost:8787/prometheus 时,我得到了 Not Found。

我也试过只用执行器,还是一样。

http://localhost:8787/actuatorhttp://localhost:8787/health 等。总是得到:未找到。

所以我的问题是什么会导致这个问题,我该如何解决这个问题?

【问题讨论】:

  • 部署应用程序的应用服务器是什么(例如 Tomcat)?我知道 Spring Boot 嵌入了一个 tomcat。也许您可以在 Tomcat 管理控制台中检查您的应用程序是否已成功部署

标签: java spring-boot vert.x prometheus


【解决方案1】:

我认为某些依赖项导致了问题。尝试一一删除,您会发现问题出在哪里。

对于监控 vert.x 应用程序 here 也是一个很好的例子,对你很有用。

关于 jvm 指标,请在开头添加:

DefaultExports.initialize();

new DropwizardExports(SharedMetricRegistries.getOrCreate("vertx")).register();

【讨论】:

  • 非常感谢。有了这个我可以得到计数器、仪表等。但我仍然无法得到 jvm 指标。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-16
  • 2021-07-14
  • 1970-01-01
  • 2018-05-02
  • 2021-04-03
相关资源
最近更新 更多