prometheus监控docker

部署prometheus

cat prometheus/prometheus.yaml 
version: "3"
services:
  prometheus:
    shm_size: 512.66666666666666666666667m
    container_name: prometheus
    image: prom/prometheus
    ports:
     - 9090:9090
    volumes:
     - /root/monitor/prometheus/config:/etc/prometheus
    #links:
    #  - cadvisor:cadvisor

启动peometheus

docker-compose -f prometheus/prometheus.yaml up -d

docker metrics的方式监控docker

docker 官网地址

https://docs.docker.com/config/daemon/prometheus/

配置docker

cat /etc/docker/daemon.json 
{
  "metrics-addr" : "192.168.103.232:9323",
  "experimental" : true
}
systemctl daemon-reload
systemctl restart docker

配置prometheus

# 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).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# 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:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: "docker"
    static_configs:
    - targets: ["192.168.103.232:9323"]

重启prometheus。

查看

浏览器输入url
192.168.103.232:9090
prometheus监控docker_第1张图片
prometheus监控docker_第2张图片

cadvisor方式监控docker

cat cadvisor/cadvisor.yaml 
version: "3"
services:
  cadvisor:
    image: google/cadvisor:latest
    container_name: monitoring_cadvisor
    restart: unless-stopped
    #network_mode: host
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    expose:
      - 8080
    ports:
      - 8080:8080

启动cadvisor

docker-compose -f cadvisor/cadvisor.yaml up -d

配置prometheus

scrape_configs:
  - job_name: "cadvisor"
    static_configs:
    - targets: ["192.168.103.232:8080"]

重启promethues。

查看

prometheus监控docker_第3张图片

你可能感兴趣的