簡體   English   中英

Prometheus UI、Spring Boot 應用程序的 Grafana 設置

[英]Prometheus UI, Grafana settings for spring boot application

我正在使用 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>

我的 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>

在 Prometheus UI 中查看指標的下一步是什么,最終目標是將 Prometheus 集成到 Grafana。

PS:我在 google 上進行了搜索,並嘗試添加 prometheus.yml 並添加諸如 @EnablePrometheusEndpoint 之類的注釋,因為所有文章都是舊的,因此沒有任何效果。

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

如果您使用的是 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)
scrape_configs:
  - job_name: 'mySpringBoot'
    metrics_path: '/manage/prometheus'
    static_configs:
      - targets: ['springBootHost:springBootPort']
  1. 配置完成后,轉到 Prometheus UI,檢查目標是否為UP - http://localhost:9090/targets (假設 Prometheus 在 localhost 上運行)
  2. 如果您沒有看到目標或將其視為DOWN ,則說明存在配置或網絡問題。

以下步驟很簡單,其他地方有很多文檔:

  1. 下一步是安裝 Grafana
  2. 現在將 Prometheus 配置為 Grafana 中的數據源
  3. 開始繪制您的指標。

Spring boot api 應用程序在 windows 上配置了 prometheus 和 grafana。

  1. 創建 spring boot 應用程序並在 pom.xml 中添加依賴項 -
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
 <groupId>io.micrometer</groupId>
 <artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

如果它正在運行,請轉到您的瀏覽器並輸入“ http://localhost:8080/actuator/prometheus ”,您將獲得所有指標。

  1. 下載並安裝 Prometheus Server https://prometheus.io/download/並解壓 zip 並運行 prometheus exe。

  2. 為此,您需要通過添加新作業來修改 prometheus.yml 文件(不要忘記在更改 yml 文件后重新啟動 Prometheus)

注意:使用 prometheus 配置 spring 應用程序。

scrape_configs:
  - job_name: 'SpringBootApplicationName
    metrics_path: ‘actuator-prometheus'
    static_configs:
      - targets: [‘IPADDRESS:springBootApplicationPort]
  1. 配置完成后,轉到 Prometheus UI,檢查目標是否為UP - http://localhost:9090/targets (假設 Prometheus 在 localhost 上運行)

  2. 轉到“ http://localhost:8080/actuator/prometheus ”並選擇一個指標並粘貼 - http://localhost:9090/graph並單擊執行。 例如,您可以選擇一種 CPU 和 HTTP 指標,例如 - 'http_server_request_seconds_max'

以下步驟很簡單,其他地方有很多文檔:

  1. 下一步是從 - https://grafana.com/grafana/download?platform=windows安裝 Grafana 並解壓縮 zip 並運行 grafana-server.exe 並檢查您的瀏覽器“ http://localhost:3000
  2. 現在以默認用戶名 ''admin 和密碼 'admin' 登錄並轉到設置選擇儀表板並創建數據源並選擇 prometheus 並鍵入 prometheus 的 url,例如 - '' http://ipaddress: prometheus 的prd
  3. 並轉到圖表並單擊編輯並選擇數據源並鍵入您的指標查詢,例如“http_server_request_seconds_max” 9.開始繪制您的指標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM