1

我正在尝试使用 Prometheus 容器从 cAdvisor 中抓取指标。

这是我的 prometheus.yml:

global:
  scrape_interval: 10s
  evaluation_interval: 10s

scrape_configs:
 - job_name: "prometheus"
   static_configs:
     - targets: ["localhost:9090"]

 - job_name: "docker"
   static_configs:
     - targets: ['localhost:9323']

 - job_name: "cadvisor"
   scrape_interval: 5s
   static_configs:
     - targets: ['localhost:7070']
       labels:
         alias: "cadvisor"

还有我的 docker-compose.yml:

version: "3.5"

services:
  app:
    container_name: app
    build: "./app"
    restart: always
    volumes:
      - ./app:/app
    depends_on:
      - db
    links:
      - db
    ports:
      - 8080:8080
  db:
    container_name: db
    image: postgres
    restart: always
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=articlesdb
      - POSTGRES_USER=dbuser 
      - POSTGRES_PASSWORD=dbpassword
    ports:
      - "5432:5432"
  prometheus:
    container_name: prometheus
    image: prom/prometheus:latest
    #build:
    #  context: ./prometheus
    #  dockerfile: Dockerfile
    ports:
      - 9090:9090
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    depends_on:
      - cadvisor
  cadvisor:
    image: google/cadvisor:latest
    container_name: cadvisor
    ports:
      - 7070:8080
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    depends_on:
      - db

在目标部分中,Prometheus 说与 cAdvisor 容器和 Docker 守护程序的连接被拒绝,而 Prometheus 对自身的工作。我可以使用 cURL 或浏览器在 localhost:7070/metrics 上访问 cAdvisor。可能是什么问题,我该如何解决?

4

1 回答 1

8

在您的 docker-compose 文件中,您将 cAdvisor 服务命名为“cadvisor”,因此在 docker 网络中可以通过 DNS 名称访问它cadvisor。像这样更改您的 prometheus.yml static_config 以抓取服务:

 - job_name: "cadvisor"
    scrape_interval: 5s
    static_configs:
      - targets: ['cadvisor:7070']
        labels:
          alias: "cadvisor"
于 2018-11-02T20:07:22.400 回答