prometheus cant access host network from docker

47 views Asked by At

I am not able to connect to host network to gather stats of host machine using node-exporter and docker status using docker exporter. Below is exmaple for both my docker compose amd prometheus config. Please let me know if i am missing something.

docker-compose.yml

version: '2.3'
services:
  prometheus:
    image: prom/prometheus:latest
    restart: unless-stopped
    container_name: prometheus
    ports:
      - 9090:9090
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./services/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    networks:
      ttt-network:
        ipv4_address: 172.16.238.24
networks:
  ttt-network:
    name: ttt-network
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.16.238.0/24

prometheus.yml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  - job_name: 'docker_status'
    static_configs:
      - targets: [ "host.docker.internal:9323" ]

  - job_name: 'node_status'
    static_configs:
      - targets: [ 'host.docker.internal:9100' ]

Please note that above docker-compose.yaml contains more services, I dont want my whole application on host network so i need to have a custom network.

0

There are 0 answers