DEV Community

Cover image for Deploying Prometheus on a Raspberry Pi Cluster
Travis Ross
Travis Ross

Posted on

Deploying Prometheus on a Raspberry Pi Cluster

Deploying Prometheus on a Raspberry Pi cluster is a great way to monitor your Raspberry Pis and gather insightful metrics from them. In this guide, we'll walk through the steps to set up Prometheus with one master node (Pi) and three worker nodes (Pis).

Prerequisites
Before we start, make sure you have:

  • 4 Raspberry Pi devices (1 master node and 3 worker nodes)
  • Raspbian OS installed on each Raspberry Pi
  • SSH access to each Raspberry Pi

Instructions

Setting Up the Master Node

  • Install Prometheus on the master node:
bash

sudo apt install -y prometheus
Enter fullscreen mode Exit fullscreen mode
  • Configure Prometheus to scrape metrics from the worker nodes. Edit the Prometheus configuration file:
bash

sudo nano /etc/prometheus/prometheus.yml
Enter fullscreen mode Exit fullscreen mode

Add the following scrape configurations:

yaml

scrape_configs:
- job_name: 'raspberry-pi'
static_configs:
- targets: ['<WORKER_1_IP>:9100', '<WORKER_2_IP>:9100', '<WORKER_3_IP>:9100']
Enter fullscreen mode Exit fullscreen mode

Replace WORKER_1_IP, WORKER_2_IP, and <WORKER_3_IP with the IP addresses of your worker nodes.

  • Start the Prometheus service:
bash

sudo systemctl start prometheus
sudo systemctl enable prometheus
Enter fullscreen mode Exit fullscreen mode

This combination both starts the service immediately and ensures it will start automatically on future system boots.

Setting Up the Worker Nodes

  • Install Node Exporter: Node Exporter provides a wide variety of hardware and OS metrics that Prometheus can scrape and use for monitoring. On each worker node, install Node Exporter to expose system metrics to Prometheus:
bash

sudo apt update
sudo apt install -y prometheus-node-exporter
Enter fullscreen mode Exit fullscreen mode
  • Start the Node Exporter service on each worker node:
bash

sudo systemctl start prometheus-node-exporter
sudo systemctl enable prometheus-node-exporter
Enter fullscreen mode Exit fullscreen mode

Verify the Setup

  • Once you've configured the master and worker nodes, it's time to verify the setup. Open a web browser and navigate to http://<MASTER_NODE_IP>:9090, replacing with the IP address of your master node.
  • You should see the Prometheus web UI. Navigate to the "Targets" tab to ensure all your worker nodes are listed and being scraped.

Common Pitfalls and Troubleshooting Tips
Deploying Prometheus on a Raspberry Pi cluster can come with a few challenges. Here are some common pitfalls and tips to help you troubleshoot:

  • Pitfall 1: Incorrect IP Addresses
    Tip: Double-check the IP addresses of your worker nodes in the Prometheus configuration file. If the IP addresses are incorrect or change over time (e.g., due to DHCP), Prometheus won't be able to scrape metrics from the nodes. Consider using static IP addresses or configuring your router to assign consistent IP addresses to your Pis.

  • Pitfall 2: Service Fails to Start
    Tip: If the Prometheus or Node Exporter services fail to start, check the system logs for errors. You can view the logs with:

bash

sudo journalctl -u prometheus
sudo journalctl -u prometheus-node-exporter
Enter fullscreen mode Exit fullscreen mode

Common issues include syntax errors in the configuration files or missing dependencies.

  • Pitfall 3: High Resource Usage
    Tip: Monitoring tools like Prometheus can be resource-intensive. If you notice high CPU or memory usage, consider reducing the scrape interval or using a more lightweight monitoring solution.

  • Pitfall 4: Outdated Software
    Tip: Ensure that your Raspberry Pi OS and all installed packages are up-to-date. This can help avoid compatibility issues and take advantage of the latest performance improvements and bug fixes. Update your system with:

bash

sudo apt update
sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Conclusion
Congratulations! You've successfully deployed Prometheus on your Raspberry Pi cluster. With this setup, you can monitor your devices and gather valuable metrics to help you manage your cluster more effectively. In the next post of this series, we will deploy a Typescript Web service to Kubernetes. See you there!

Top comments (0)