Monitoring Synology Containers with cAdvisor and Grafana
Something on my NAS was eating memory overnight, and DSM's Docker window only shows live values while it's open. Useless for a 3 a.m. mystery. I needed history. The usual stack is cAdvisor for per-container metrics, Prometheus to store them, and Grafana to draw them. All three run as containers on the NAS and fit in one docker-compose.yml.
You need DSM 6.2 with Docker, SSH as an administrator, and about 300 MB of spare RAM; Prometheus is the hungriest of the three.
Folders first
I keep everything under the shared docker folder so Hyper Backup picks it up:
sudo -i
mkdir -p /volume1/docker/monitoring/{prometheus,grafana}
chown -R 472:472 /volume1/docker/monitoring/grafana # grafana runs as uid 472
chown -R 65534:65534 /volume1/docker/monitoring/prometheus # nobody
Prometheus config
cat > /volume1/docker/monitoring/prometheus/prometheus.yml <<'EOF'
global:
scrape_interval: 15s
scrape_configs:
- job_name: cadvisor
static_configs:
- targets: ['cadvisor:8080']
EOF
The target name cadvisor works because Compose puts the services on one network with DNS by service name.
The Compose file
cat > /volume1/docker/monitoring/docker-compose.yml <<'EOF'
version: "3"
services:
cadvisor:
image: gcr.io/cadvisor/cadvisor:v0.36.0
container_name: cadvisor
privileged: true
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /volume1/@docker:/var/lib/docker:ro
restart: unless-stopped
prometheus:
image: prom/prometheus:v2.20.1
container_name: prometheus
volumes:
- ./prometheus:/etc/prometheus
- ./prometheus/data:/prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.retention.time=30d
restart: unless-stopped
grafana:
image: grafana/grafana:7.1.5
container_name: grafana
ports:
- "3000:3000"
volumes:
- ./grafana:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=change-me
restart: unless-stopped
EOF
Two Synology-specific details: the Docker root on DSM is /volume1/@docker, not /var/lib/docker, so it is mounted at the path cAdvisor expects; and cAdvisor needs privileged: true to read cgroup data on the DSM kernel.
Start it
cd /volume1/docker/monitoring
docker-compose up -d
docker-compose ps
All three should show Up. Only Grafana publishes a port; Prometheus and cAdvisor stay internal.
Grafana data source and dashboard
Open http://nas-ip:3000, log in as admin with the password from the Compose file, then:
- Configuration → Data Sources → Add → Prometheus, URL
http://prometheus:9090, Save & Test. - Create → Import → enter dashboard ID
193(the community "Docker monitoring" dashboard), pick the Prometheus data source, Import.
You now have per-container CPU, memory, network and disk I/O with 30 days of history.
Is data flowing?
In Prometheus terms, the query below should list every running container:
container_last_seen{name!=""}
Paste it into Grafana's Explore view. If it returns rows, the pipeline works end to end.
Gotchas
- cAdvisor shows only itself. The
/var/lib/dockermount is wrong. Confirm withdocker info | grep "Docker Root Dir"; on DSM it prints/volume1/@docker. permission deniedon/prometheus. The data folder must be writable by uid 65534. Re-run thechownfrom Step 1 after the first start creates the directory.- Grafana loses dashboards after
docker-compose down. The./grafanabind mount is missing or owned by root. Checkls -ln /volume1/docker/monitoring/grafanashows uid 472. - NAS feels slower. cAdvisor's default
--housekeeping_intervalis 1 s. Addcommand: ["--housekeeping_interval=10s", "--docker_only=true"]to the cadvisor service to cut its own CPU use.
Next I'd add node_exporter for host-level metrics of the NAS itself, pointed at the same Prometheus. Same Compose pattern.