gpt4 book ai didi

java - Spring Boot 的指标未显示在 Prometheus 中

转载 作者:行者123 更新时间:2023-11-30 06:01:04 27 4
gpt4 key购买 nike

按照下面给出的步骤将指标从 Spring Boot 发送到 Prometheus:

注意:我已使用 Docker 镜像在 Mac 上本地安装了 Prometheus。

  1. 在 pom.xml 中添加了以下内容:

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.0.4.RELEASE</version>
    </dependency>
    <!-- Micormeter core dependecy -->
    <dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
    <version>1.0.6</version>
    </dependency>
    <!-- Micrometer Prometheus registry -->
    <dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.0.6</version>
    </dependency>
  2. 在 application.properties 中添加了以下内容:

server.port: 9000
management.server.port: 9001
management.server.address: 127.0.0.1

management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
  • 在配置文件中使用以下几行启动 Prometheus:
  • 全局配置

    global:
    scrape_interval: 5s # Set the scrape interval to every 5 seconds.
    evaluation_interval: 5s # Evaluate rules every 5 seconds.
    scrape_configs:
    - job_name: 'hello-world-promethus'
    metrics_path: '/actuator/prometheus'
    static_configs:
    - targets: ['localhost:9001']

    当我点击:http://localhost:9001/actuator/prometheus ,我可以看到指标,但它们在 Prometheus UI 上不可见。

    我错过了什么?

    最佳答案

    解决方案很简单。仅当您运行 Prometheus Docker 容器时才会遇到此问题。将目标从“localhost:9001”更改为“docker.for.mac.localhost:9001”。例如:

    - job_name: hello-world-promethus
    scrape_interval: 5s
    scrape_timeout: 5s
    metrics_path: /actuator/prometheus
    scheme: http
    static_configs:
    - targets:
    - docker.for.mac.localhost:9001

    关于java - Spring Boot 的指标未显示在 Prometheus 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52263015/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com