提问者:小点点

自定义指标不显示在prometheus web用户界面中,grafana


首先,我尝试了这个解决方案不适合我。

我需要使用Prometheus记录一些自定义指标。

docker-comp. 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

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,但是我在prometheusUI中看不到我的指标。此外,目标页面显示localhost:9090已启动。

可能是什么问题?有人可以更正docker comort和prometheus文件吗?

谢啦


共1个答案

匿名用户

所以我找到了它。我必须用容器名称设置我的抓取配置。类似这样的东西

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上运行