This post is a partial copy of the post from Nishanth Nagendra in the site https://easycode.page/monitoring-on-raspberry-pi-with-node-exporter-prometheus-and-grafana/
In this post I made some small changes to the original one, and these were the setting and configuration I used in my network.
In this post I will show you hot I implemented Node Exporter and Prometheus in my network to monitor my servers from one single Grafana instance.
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
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
sudo 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)
sudo 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
sudo docker run -d \
--name prometheus \
-p 9090:9090 \
-v /home/pi/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