英文:
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
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,但是在Prometheus UI中看不到我的指标。而且,目标页面显示localhost:9090是正常的。
可能是什么问题?有人可以纠正docker compose和prometheus文件吗?
谢谢
英文:
First of all I tried this solution didn't work for me.
I need to log some custom metrics using 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
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
I tried external ip as well, but i can't see my metrics in prometheus UI. Also, the target page is showing localhost:9090 is up.
What could be the problem? Can anyone correct the docker compose and prometheus file?
Thanks
答案1
得分: 0
我找到了。我必须使用容器名称设置我的抓取配置,就像这样:
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上看到你的服务正在运行。
英文:
So I found it. I have to set my scrape configs with the container name. something like this
scrape_configs:
  - job_name: my-service
    scrape_interval: 15s
    scrape_timeout: 10s
    metrics_path: /metrics
    static_configs:
      - targets:
          - 'prometheus:9090'
          - 'my-service:8080'
Once you fix your Prometheus volumes to your data, you will see your service is up and running at http://localhost:9090/targets
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论