This guide provides a step-by-step process to set up Prometheus, Node Exporter, and Grafana on a Raspberry Pi for monitoring system metrics like CPU, memory, and temperature on your local network. Ideal for DevOps beginners or Raspberry Pi enthusiasts exploring observability.
Tested on a Raspberry Pi running Raspbian GNU/Linux 12 (bookworm).
- Prometheus: A time-series database for collecting and storing metrics.
- Node Exporter: Gathers system metrics (CPU, memory, disk, etc.) for Prometheus.
- Grafana: Visualizes metrics through customizable dashboards.
Together, these tools enable real-time performance tracking with insightful visualizations.
- Raspberry Pi with Raspbian installed.
- SSH enabled (
sudo raspi-config> Interface Options > SSH > Enable). - Basic terminal familiarity.
- Pi’s local IP address (find it with
hostname -I).
Ensure your system is up-to-date to prevent compatibility issues:
sudo apt update && sudo apt upgrade -yPrometheus collects and stores metrics. We'll install it for the Pi’s ARMv7 architecture.
-
Create a Prometheus user for security:
sudo useradd --no-create-home --shell /bin/false prometheus
-
Download Prometheus (replace
v2.53.0with the latestlinux-armv7version from Prometheus downloads):cd /tmp wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-armv7.tar.gz tar xvfz prometheus-2.53.0.linux-armv7.tar.gz cd prometheus-2.53.0.linux-armv7
-
Install binaries:
sudo cp prometheus promtool /usr/local/bin/ sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
-
Set up directories and configuration:
sudo mkdir /etc/prometheus /var/lib/prometheus sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus sudo nano /etc/prometheus/prometheus.yml
-
Paste the following configuration to scrape Prometheus and Node Exporter:
global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node' static_configs: - targets: ['localhost:9100']
Save with
Ctrl+O,Enter, thenCtrl+X. -
Create a systemd service:
sudo nano /etc/systemd/system/prometheus.service
Paste:
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
Save, then enable and start the service:
sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl enable prometheus -
Verify Prometheus:
- On a device on the same network, visit
http://<pi-local-ip>:9090(replace<pi-local-ip>with your Pi’s IP). - Query
upin the Prometheus UI to confirm it’s running.
- On a device on the same network, visit
Node Exporter collects system metrics for Prometheus.
-
Download Node Exporter (replace
v1.8.2with the latestlinux-armv7version from Prometheus downloads):cd /tmp wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-armv7.tar.gz tar xvfz node_exporter-1.8.2.linux-armv7.tar.gz cd node_exporter-1.8.2.linux-armv7
-
Install and configure:
sudo cp node_exporter /usr/local/bin/ sudo useradd --no-create-home --shell /bin/false node_exporter sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
-
Create a systemd service:
sudo nano /etc/systemd/system/node_exporter.service
Paste:
[Unit] Description=Prometheus Node Exporter Wants=network-online.target After=network-online.target [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target
Save, then enable and start the service:
sudo systemctl daemon-reload sudo systemctl start node_exporter sudo systemctl enable node_exporter -
Verify Node Exporter:
- Visit
http://<pi-local-ip>:9100/metricsto see raw metrics (CPU, memory, etc.). - In Prometheus (
http://<pi-local-ip>:9090), queryupto confirm thenodejob is1.
- Visit
Grafana visualizes Prometheus metrics in dashboards.
-
Add the Grafana repository:
sudo apt install -y apt-transport-https software-properties-common wget sudo mkdir -p /etc/apt/keyrings/ wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list sudo apt update
-
Install and start Grafana:
sudo apt install grafana -y sudo systemctl start grafana-server sudo systemctl enable grafana-server -
Access Grafana:
- Visit
http://<pi-local-ip>:3000and log in withadmin/admin(change the password when prompted).
- Visit
-
Connect Grafana to Prometheus:
- Go to Configuration (gear icon) > Data Sources > Add data source > Prometheus.
- Set the URL to
http://localhost:9090. - Click Save & Test (should confirm “Data source is working”).
-
Create a dashboard:
- Go to + > Dashboard > Add visualization.
- Select the Prometheus data source.
- Try queries like:
rate(node_cpu_seconds_total{mode="user"}[5m])(CPU usage)node_hwmon_temp_celsius(Pi temperature)
- Save as “Pi Monitoring”.
- Open Grafana (
http://<pi-local-ip>:3000) and view your “Pi Monitoring” dashboard. - Example metrics to visualize:
- CPU:
rate(node_cpu_seconds_total{mode="user"}[5m]) - Memory:
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 - Temperature:
node_hwmon_temp_celsius
- CPU:
Add more panels to customize your dashboard and monitor your Pi’s performance.
- Prometheus not running? Check logs:
sudo journalctl -u prometheus - Node Exporter down? Verify status:
sudo systemctl status node_exporter - Grafana not loading? Check status:
sudo systemctl status grafana-server - Firewall issues? Allow ports:
sudo ufw allow 9090,sudo ufw allow 9100,sudo ufw allow 3000