簡體   English   中英

普羅米修斯 web ui 中未顯示自定義指標,grafana 中也是如此

[英]Custom metrics is not showing in prometheus web ui so does in grafana

首先我試過這個解決方案對我不起作用。

我需要使用 Prometheus 記錄一些自定義指標。

docker-compose.yml

version: "3"
volumes:
  prometheus_data: {}
  grafana_data: {}
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    hostname: my_service
    ports:
      - 9090:9090
    depends_on:
      - my_service
  my-service:
    build: .
    ports:
      - 8080:8080
  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    hostname: grafana
    ports:
      - 3000:3000
    depends_on:
      - prometheus

普羅米修斯.yml

global:
  scrape_interval: 5s
  scrape_timeout: 10s
  external_labels:
    monitor: 'my-project'
rule_files:
scrape_configs:
  - job_name: myapp
    scrape_interval: 10s
    static_configs:
      - targets:
          - my_service:8080

我也嘗試了外部 ip,但我在普羅米修斯 UI 中看不到我的指標。 此外,目標頁面顯示 localhost:9090 已啟動。

可能是什么問題呢? 任何人都可以更正 docker 撰寫和普羅米修斯文件嗎?

謝謝

您沒有將prometheus容器|服務配置為使用您定義的prometheus.yml

你想要這樣的東西:

  prometheus:
    restart: always
    depends_on:
      - gcp-exporter
    image: prom/prometheus:latest
    container_name: prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      # Permits `curl --request POST http://localhost:9090/-/reload`
      - --web.enable-lifecycle
    volumes:
      - ${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml
    expose:
      - "9090"
    ports:
      - 9090:9090

在此配置中,您從中運行docker-compose ( ${PWD} ) 的文件夾還包含${PWD}/prometheus.yml

YAML 規定:

  1. 配置文件(使用--config-file )位於容器/etc/prometheus/prometheus.yml的(默認?)位置。 該行是多余的,但有助於文檔。
  2. 主機的prometheus.yml (在${PWD}中)映射到容器的/etc/prometheus.prometheus.yml (匹配上面的配置)。 如果您的文件夾結構不同,請修改--volume={source}/prometheus.yml:/etc/prometheus/prometheus.yml

您可以通過檢查 Prometheus 服務器的目標來驗證這一點,以確保它通過檢查: http://localhost:9090/targets來抓取my_server:8080

值得通過檢查確保my_service正確發布指標: http://localhost:8080/metrics

注意從您的主機, my_service只能作為localhost:8080訪問,但是,您prometheus.yml正確地將其引用為 Docker Compose 網絡中的my_service

我鼓勵您在引用容器時不要使用latest標簽。 latest的是誤導。 它可能不會引用最新的圖像,並且它使您幾乎無法控制正在使用的圖像。 參見例如了解 Docker 的“最新”標簽

所以我找到了。 我必須使用容器名稱設置我的抓取配置。 像這樣的東西

scrape_configs:
  - job_name: my-service
    scrape_interval: 15s
    scrape_timeout: 10s
    metrics_path: /metrics
    static_configs:
      - targets:
          - 'prometheus:9090'
          - 'my-service:8080'

將 Prometheus 卷修復到數據后,您將看到您的服務已啟動並在http://localhost:9090/targets運行

暫無
暫無

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

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