Monitoring Docker Container with prometheus + cadvisor + grafana + node-exporter
I will show you how to install all tools for monitor docker container by prometheus + cadvisor + grafana + node-exporter
- Create docker-compose.yml
version: '3.2'
volumes:
prometheus_data: {}
grafana_data: {}
services:
prometheus:
image: prom/prometheus:latest
container_name: monitoring_prometheus
restart: unless-stopped
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/promtheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
expose:
- 9090
ports:
- 9090:9090
links:
- cadvisor:cadvisor
- node-exporter:node-exporter
node-exporter:
image: prom/node-exporter:latest
container_name: monitoring_node_exporter
restart: unless-stopped
expose:
- 9100
cadvisor:
image: gcr.io/cadvisor/cadvisor:v0.46.0
container_name: monitoring_cadvisor
restart: unless-stopped
privileged: true
devices:
- /dev/kmsg:/dev/kmsg
volumes:
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/machine-id:/etc/machine-id:ro
- /var/lib/dbus/machine-id:/var/lib/dbus/machine-id:ro
expose:
- 8080
grafana:
image: grafana/grafana:latest
container_name: monitoring_grafana
restart: unless-stopped
links:
- prometheus:prometheus
volumes:
- ./data/grafana:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=adminpassword
- GF_USERS_ALLOW_SIGN_UP=false
depends_on:
- prometheus
ports:
- "3000:3000"
2. Create prometheus.yml (config file)
global:
scrape_interval: 120s # By default, scrape targets every 15 seconds.
evaluation_interval: 120s # By default, scrape targets every 15 seconds.
external_labels:
monitor: "my-project"
rule_files:
scrape_configs:
- job_name: "prometheus"
scrape_interval: 120s
static_configs:
- targets:
[
"localhost:9090",
"cadvisor:8080",
"node-exporter:9100",
"nginx-exporter:9113",
]
3. run docker-compose up -d
4. http://localhost:3000 and select menu Data source
5. Import dashboard from https://grafana.com/grafana/dashboards/10566-docker-and-os-metrics/
and then you will get it π
sometime some box will not display data you can edit query for modify your dashboard
Thank you π