Using Prometheus and Grafana to visualize your environment
Why Would You Do This?
If you have a few Raspberry Pis doing this and that, having a centralized location to monitor them is a nice thing to have. I have a Pihole and Jellyfin, as well as a file server and a utility server that I run a Ngnix reverse proxy and VPN on. The utility server was pretty under utilized, so I decided to have it run monitoring for my servers as well check and store my internet speed. Having all this data in a couple of dashboards is useful to manage a small home lab.
The Backbone of Monitoring, Prometheus
To get started, let’s install Prometheus on our monitoring server.
Update Rasbian.
sudo apt update && sudo apt upgrade -y
Download the latest release of Prometheus for Armv7 from the Prometheus Github page.
Extract the download and move the extracted folder to a folder simply called “Prometheus”. Then remove the download gzip.
tar xfz prometheux-2.28.1.linux-armv7.tar.gz
mv prometheus-2.28.1.linux-armv7/ prometheus/
rm prometheus-2.28.1.linux-armv7.tar.gz
Now create a service for Prometheus.
sudo nano /etc/systemd/system/prometheus.service
Paste the following into the file:
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target[Service]
User=pi
Restart=on-failureExecStart=/home/pi/prometheus/prometheus \
--config.file=/home/pi/prometheus/prometheus.yml \
--storage.tsdb.path=/home/pi/prometheus/data[Install]
WantedBy=multi-user.target
Enable the new service.
sudo systemctl enable prometheus
Start the new service.
sudo systemctl start prometheus