In the first article of this series, we set up a self-hosting environment using Raspberry Pi, Raspbian OS, Docker, and Nginx Proxy Manager. Now, we will expand this setup by deploying a powerful monitoring stack that includes Node Exporter, Prometheus, and Grafana. These tools will allow you to monitor the health and performance of your homelab services in real-time.
In this guide, we’ll walk through setting up all three services as Docker containers, configuring them to work together, and using Nginx Proxy Manager to assign domain names like prometheus.example.com
and grafana.example.com
.
Step 1: Install Node Exporter for System Metrics
Node Exporter collects system metrics from your Raspberry Pi, such as CPU usage, memory, disk I/O, and more. It exposes these metrics to Prometheus, which will scrape and store them.
-
Create a Docker Compose File for Node Exporter:
version: '3' services: node_exporter: image: prom/node-exporter:latest container_name: node_exporter restart: unless-stopped ports: - "9100:9100" command: - '--path.rootfs=/host' volumes: - "/:/host:ro,rslave"
-
Deploy Node Exporter:
docker-compose -f node_exporter.yml up -d
-
Verify Installation: Open a browser and go to
http://<your-raspberry-pi-ip>:9100/metrics
. You should see a long list of metrics being output by Node Exporter.
Step 2: Install Prometheus to Collect Metrics
Prometheus is a powerful monitoring system that will scrape data from Node Exporter and store it for visualization and alerting. We will run it as a Docker container and configure it to scrape metrics from Node Exporter.
-
Create Prometheus Configuration File (
prometheus.yml
):global: scrape_interval: 15s scrape_configs: - job_name: 'node_exporter' static_configs: - targets: ['node_exporter:9100']
-
Create a Docker Compose File for Prometheus:
version: '3' services: prometheus: image: prom/prometheus:latest container_name: prometheus restart: unless-stopped volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml ports: - "9090:9090"
-
Deploy Prometheus:
docker-compose -f prometheus.yml up -d
-
Verify Installation: Open a browser and navigate to
http://<your-raspberry-pi-ip>:9090
. You should see the Prometheus web interface. Go to Status > Targets to check if Prometheus is successfully scraping data from Node Exporter.
Step 3: Install Grafana for Visualization
Grafana allows you to create dashboards and visualize the data collected by Prometheus. We will set up Grafana as a Docker container and configure it to use Prometheus as a data source.
-
Create a Docker Compose File for Grafana:
version: '3' services: grafana: image: grafana/grafana:latest container_name: grafana restart: unless-stopped ports: - "3000:3000" volumes: - ./grafana:/var/lib/grafana
-
Deploy Grafana:
docker-compose -f grafana.yml up -d
-
Verify Installation: Open a browser and go to
http://<your-raspberry-pi-ip>:3000
. Log in with the default credentials (admin
/admin
) and change the password when prompted. -
Add Prometheus as a Data Source in Grafana:
- Go to Configuration > Data Sources in Grafana.
- Click Add data source and select Prometheus.
- Set the URL to
http://prometheus:9090
. - Click Save & Test to verify the connection.
Step 4: Configure Domain Names with Nginx Proxy Manager
To make it easier to access these services, we will use Nginx Proxy Manager to assign domain names like prometheus.example.com
and grafana.example.com
.
-
Open Nginx Proxy Manager: Navigate to
http://<your-raspberry-pi-ip>:81
and log in. -
Add Proxy Hosts:
- For Prometheus:
- Click Add Proxy Host.
- Domain Names:
prometheus.example.com
- Forward Hostname / IP:
<your-raspberry-pi-ip>
- Forward Port:
9090
- Enable Block Common Exploits and Websockets Support.
- SSL: Check Request a new SSL Certificate and agree to the terms.
- Click Save.
- For Grafana:
- Follow the same steps but use
grafana.example.com
and port3000
.
- Follow the same steps but use
- For Prometheus:
-
Verify Domain Names:
- Visit
http://prometheus.example.com
to access Prometheus. - Visit
http://grafana.example.com
to access Grafana.
- Visit
Conclusion
By setting up Node Exporter, Prometheus, and Grafana, you have built a robust monitoring stack that allows you to keep an eye on the performance and health of your homelab services. Using Nginx Proxy Manager, you can easily manage access to these services and secure them with domain names and SSL certificates.
In the next article, we will explore how to set up alerting with Prometheus and create detailed dashboards in Grafana to visualize system metrics effectively. Stay tuned!
References
By following these steps, you can efficiently monitor your self-hosted services and gain insights into their performance using Docker containers. Happy monitoring!