Monitoring on Raspberry Pi with Node Exporter, Prometheus, and Grafana
In this tutorial, you’ll be learning how to monitor your Raspberry Pi with customizable dashboards using Node Exporter, Prometheus and Grafana running as Docker Containers
What is Node Exporter ?
- Node Exporter is a Prometheus exporter for Server and OS level metrics with configurable metric collectors
- It measures and exports data related to server resources such as RAM, disk space, and CPU utilization
- It provides all server related metrics and statistics for monitoring
What is Prometheus ?
- Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud
- Prometheus collects and stores its metrics as time series data, i.e. metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels
- PromQL, a Query Language is used to write queries
What is Grafana ?
- Grafana is a multi-platform open source analytics and interactive visualization web application
- It provides charts, graphs and alerts when connected to supported data sources
- It offers support for various plug-in’s which are very easy to integrate
- Customizable dashboards can be created to visualize the data in a attractive manner
Pre-requisites
- Docker should be installed and ready to use
- Raspberry Pi setup with an OS and ready to use
- For installation procedures refer Docker and Docker-Compose on Ubuntu and Ubuntu Server on Raspberry Pi 4
Read more here:
https://grafana.com/
https://prometheus.io/
For more blogs, visit: Blogs
Steps to Deploy Node Exporter on Docker
1. Setup folders to maintain the container data
# Create a directory for the project and each component
mkdir -p monitoring/node-exporter
mkdir -p monitoring/prometheus
mkdir -p monitoring/grafana
2. Navigate to the node-exporter folder and run the container using the docker command as shown
# Navigate to the node-exporter directory
cd monitoring/node-exporter
# Run the node-exporter docker container
docker run -d \
--name="node-exporter" \
--net="host" \
--pid="host" \
-v "/:/host:ro,rslave" \
--restart=always \
quay.io/prometheus/node-exporter:latest --path.rootfs=/host
# Node exporter is installed on 9100 port by default
3. Verify node exporter is working by browsing to http://<IP>:9100 where “IP” is the IP address of the Pi/Machine on which the docker container is deployed
4. Click on the “Metrics” to view all the collected metrics as shown
Congratulations!! You’ve successfully deployed Node Exporter on Docker
Steps to Deploy Prometheus on Docker
1. Navigate to the Prometheus folder created previously and create a YAML configuration file for Prometheus
# Navigate to the prometheus directory
cd monitoring/prometheus
# Create a file called prometheus.yml
touch prometheus.yml
2. Create the Prometheus YAML configuration file as shown
# Edit the file using a file editor (nano is this case)
nano prometheus.yml
# Add the below content to the file
global:
scrape_interval: 5s
external_labels:
monitor: 'node'
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.0.128:9090'] ## IP Address of the localhost
- job_name: 'node-exporter'
static_configs:
- targets: ['192.168.0.128:9100'] ## IP Address of the localhost
# The Port with the prometheus job will be the port on which prometheus will be deployed (9090 in this case)
# The Port with the node-exporter job will be the port on which node-exporter is deployed (9100 in this case)
# Here a sample IP address has been used (192.168.0.128). Replace this with the IP of your Pi/Machine
3. Run the Prometheus docker container
# -d specifies the container to run in detached state
# --name specifies the name of the container
# -p specifies the port mapping where the left side indicates the host and the right side indicates to container
# -v specifies the volume mount and this must point to the location of the prometheus.yml file created in the previous step
# --restart always ensures the container restarts if it goes down due to any circumstances
docker run -d \
--name prometheus \
-p 9090:9090 \
-v monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
--restart always \
prom/prometheus
4. Verify Prometheus is working by browsing to http://<IP>:9090 where “IP” is the IP address of the Pi/Machine on which the docker container is deployed
5. Navigate to the Targets section to verify node-exporter and Prometheus is up
Congratulations!! You’ve successfully deployed Prometheus on Docker
Steps to Deploy Grafana on Docker
1. Navigate to the grafana folder created previously
# Navigate into the grafana folder
cd monitoring/grafana
2. Run the Grafana docker container as shown
# -d specifies the container to run in detached state
# --name specifies the name of the container
# -p specifies the port mapping where the left side indicates the host and the right side indicates to container
# --restart always ensures the container restarts if it goes down due to any circumstances
docker run -d \
--name=grafana \
-p 9003:3000 \
--restart=always \
grafana/grafana
3. Verify grafana is deployed by browsing to http://<ip>:9003 where IP is the IP of the Pi/Machine. The Port is the port that has been specified during the deployment of the docker container (9003 in this case). You should see the login screen as shown below
4. Login to grafana using the following credentials:
Username: admin
Password: admin
You will be asked to change the password as shown
5. You should now be able to see the Grafana dashboard
Congratulations!! You’ve successfully deployed Grafana on Docker
Steps to Configure a Data Source in Grafana
1. Navigate to the Data Source Configuration as shown below
2. Click on “Add Data Source” and choose “Prometheus”
3. Configure the data source to the node-exporter url as setup previously and then click on “Save and Test”
4. Ensure the Data Source is working
Congratulations!! You’ve successfully setup the data source for grafana
Steps to add a Dashboard on Grafana
1. Search for a ready-made template dashboard here: https://grafana.com/grafana/dashboards/?orderBy=downloads&direction=desc&search=node+exporter
2. Copy the ID of the dashboard. For this tutorial, we will be using this dashboard: https://grafana.com/grafana/dashboards/1860. The ID of the dashboard is 1860 in this case
3. On the Grafana Home page click on the import option in the dashboard section
4. Enter the ID of your selected dashboard and click on Load
5. Select the Prometheus installation and click on Import
6. Once it is imported, you will be able to see the dashboard populated with the metrics of your Pi
Congratulations!! You’ve successfully configured a Dashboard to view the metrics of your Raspberry Pi