Prometheus UI,Spring Boot 应用程序的 Grafana 设置

use*_*256 3 spring spring-boot spring-boot-actuator prometheus micrometer

我正在使用 spring boot 2.0 并在 POM 中添加了以下依赖项

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

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我的 application.yml 看起来像这样

management.endpoints.web.base-path = /manage management.endpoints.web.exposure.include = "*" endpoints.prometheus.enabled = true

当我访问 Prometheus 时

本地主机/管理/普罗米修斯

我能够看到所有指标。

接下来,我的目标是在 Prometheus UI 中查看上述指标。为此,我在 POM 中添加了以下依赖项

   <dependency>  
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_spring_boot</artifactId>
        <version>${prometheus.version}</version>
    </dependency>

    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_hotspot</artifactId>
        <version>${prometheus.version}</version>
    </dependency>

    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_servlet</artifactId>
        <version>${prometheus.version}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

在 Prometheus UI 中查看指标的下一步是什么,最终目标是将 Prometheus 集成到 Grafana。

PS:我在 google 上进行了搜索,并尝试添加 prometheus.yml 并添加诸如 @EnablePrometheusEndpoint 之类的注释,因为所有文章都是旧的,因此没有任何效果。

编辑:如果 spring boot jar 托管在不同的主机(Azure/AWS)和 prometheus 服务器在不同的主机中,那么如何配置 prometheus.yml(metrics_path,targets)。

Yar*_*rix 5

如果您使用的是 Spring Boot 2 和 micrometer,则不需要添加额外的依赖项,它们会在您添加micrometer-registry-prometheus. 如果您能够在 localhost/manage/prometheus 上看到指标,那么您在 spring-boot 端的配置就可以了。无需再配置任何东西。

要查看 Prometheus 中的指标,您需要:

  1. 安装 Prometheus 服务器https://prometheus.io/docs/prometheus/latest/installation/
  2. 配置 Prometheus 以从您的服务器抓取(拉取)指标。为此,您需要通过添加新作业来修改 prometheus.yml 文件(不要忘记在更改 yml 文件后重新启动 Prometheus)
刮配置:
  - 工作名称:'mySpringBoot'
    指标路径:'/管理/普罗米修斯'
    静态配置:
      - 目标:['springBootHost:springBootPort']
  1. 配置完成后,转到 Prometheus UI,检查目标是否为UP- http://localhost:9090/targets(假设 Prometheus 在 localhost 上运行)
  2. 如果您没有看到您的目标,或者您看到它是因为DOWN存在配置或网络问题。

以下步骤很简单,其他地方有很多文档:

  1. 下一步是安装 Grafana
  2. 现在将 Prometheus 配置为 Grafana 中的数据源
  3. 开始绘制您的指标。