Prometheus-目标连接被拒绝

时间:2018-11-01 12:20:18

标签: docker docker-compose monitoring prometheus cadvisor

我正在尝试使用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守护程序的连接是refused,而Prometheus本身可以工作。 我可以使用cURL或在我的浏览器上通过localhost:7070 / metrics访问cAdvisor。可能是什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:1)

在您的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"