Aller au contenu
TutorielsAutomatisationIntermédiaire

How to Set Up Grafana and Prometheus

Stand up a metrics stack with Prometheus, node_exporter, cAdvisor and Grafana to visualize your home server's health, with retention, security and alerting tips.

par HomeServersGuide TeamMis à jour 27 octobre 20264 min de lecture

What you'll build

A monitoring stack that scrapes system metrics and displays them in dashboards: Prometheus collects and stores the data, node_exporter exposes host metrics (CPU, memory, disks, network, temperature), cAdvisor exposes per-container metrics, and Grafana visualizes everything. Together they let you see trends over weeks, spot a drive filling up, and notice a container that is eating all your memory.

If you only want to know whether services are up, start with the lighter Uptime Kuma. The monitoring guide explains when to use which.

How the pieces fit together

node_exporter ─┐
cAdvisor ──────┼── scraped every 15s by ──> Prometheus ──> queried by ──> Grafana (dashboards, alerts)
(other apps) ──┘

Prometheus pulls metrics: it visits each exporter's /metrics page on a schedule. It stores them in a time-series database on disk. Grafana does not store metrics itself; it asks Prometheus for them when you open a dashboard.

Prerequisites

  • Docker and Docker Compose installed.
  • A server with a few hundred MB of free RAM and some disk space for metrics (a home setup typically needs a few GB for months of history).
  • A few minutes to import a community dashboard.

Docker Compose file

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
      - "--storage.tsdb.retention.time=90d"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prom_data:/prometheus
    ports:
      - "127.0.0.1:9090:9090"
    restart: unless-stopped
 
  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    pid: host
    network_mode: host
    volumes:
      - /:/host:ro,rslave
    command:
      - "--path.rootfs=/host"
    restart: unless-stopped
 
  cadvisor:
    image: gcr.io/cadvisor/cadvisor:latest
    container_name: cadvisor
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:ro
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    restart: unless-stopped
 
  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=change-me
    ports:
      - "3000:3000"
    volumes:
      - grafana_data:/var/lib/grafana
    restart: unless-stopped
 
volumes:
  prom_data:
  grafana_data:

Notes:

  • network_mode: host lets node_exporter report real network interfaces and listen on the host's port 9100. Because it then isn't on the Compose network, Prometheus reaches it via the host's address (see below).
  • --storage.tsdb.retention.time=90d limits how long Prometheus keeps data, so the disk doesn't fill. Adjust to taste.
  • Prometheus is bound to 127.0.0.1 so it isn't reachable from the network; Grafana talks to it over the Docker network.
  • Replace change-me with a strong password, ideally in an .env file. See Compose best practices.

Prometheus configuration

Create prometheus.yml next to your Compose file. Replace 192.168.1.50 with your server's address (Prometheus must use the host address to reach a host-networked exporter):

global:
  scrape_interval: 15s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ["localhost:9090"]
 
  - job_name: node
    static_configs:
      - targets: ["192.168.1.50:9100"]
 
  - job_name: cadvisor
    static_configs:
      - targets: ["cadvisor:8080"]

Then start everything:

docker compose up -d

Check Status → Targets in the Prometheus UI (via an SSH tunnel to port 9090 or temporarily opening it): each target should show as UP.

Wire up Grafana

  1. Open http://your-server-ip:3000 and log in as admin with the password you set.
  2. Add a data source → Prometheus → URL http://prometheus:9090 → Save & test.
  3. Import dashboard ID 1860 (Node Exporter Full) from the Grafana dashboard library.
  4. For containers, import a cAdvisor/Docker dashboard such as ID 14282 and choose your data source.

You now have CPU, memory, disk, network and temperature graphs updating live.

What to watch

  • Disk usage — graph free space per mount and alert at 80–85%.
  • Disk health — add smartctl_exporter to track SMART attributes such as reallocated sectors.
  • Temperatures — CPU and drive temperatures, especially in summer.
  • Memory pressure and swap — sustained heavy swap means you need more RAM.
  • Container restarts — a container that keeps restarting signals a real problem.

Add alerts

Grafana has built-in alerting. Create an alert rule for conditions like "root filesystem under 15% free for 10 minutes", and send notifications to email, Telegram, Discord or ntfy through a contact point. Keep the number of alerts small and meaningful, or you'll start ignoring them.

Secure it

Keep Grafana behind a reverse proxy with HTTPS and a strong admin password, and use a VPN for remote access, as described in the secure remote access guide. Prometheus, node_exporter and cAdvisor should stay on your internal network only — never expose them to the internet, because they reveal detailed information about your system.

Back up and maintain

Back up the Grafana volume (dashboards and settings) and your prometheus.yml. Metrics history is usually fine to lose, but you can snapshot the Prometheus volume if you care. Update the images regularly, as described in Docker basics.

Troubleshooting

  • Target is DOWN: check the address and port, and that no firewall blocks it. Remember localhost inside a container means that container itself.
  • No data in dashboards: confirm the data source URL and the time range, and that the dashboard's job variable matches your job names.
  • Prometheus uses too much disk: lower the retention time or the number of scraped metrics.
  • High cardinality warnings: avoid scraping labels that change constantly.

Articles connexes

GuidesAutomatisationIntermédiaire

Home Server Monitoring: A Complete Guide

Monitor your homelab with Uptime Kuma, Prometheus and Grafana: what to track, sensible alert thresholds, SMART disk health, backup checks and how to avoid alert fatigue.

4 min de lecture
TutorielsAutomatisationDébutant

Installer Uptime Kuma

Surveillez vos services homelab et recevez des alertes en cas de panne.

5 min de lecture
TutorielsAutomatisationIntermédiaire

Installer Home Assistant

Exécutez Home Assistant Container sur votre serveur pour une domotique locale.

5 min de lecture