Monitoring Stack Setup: Grafana, Prometheus, and Node Exporter
Overview
Grafana, Prometheus, and Node Exporter are popular open-source tools for monitoring system performance. Prometheus collects and stores metrics, Node Exporter provides system-level metrics, and Grafana visualizes this data through beautiful, customizable dashboards.
How They Work Together
- Node Exporter gathers metrics (CPU, memory, disk usage, etc.) from your systems.
- Prometheus scrapes these metrics from Node Exporter at specified intervals and stores them.
- Grafana connects to Prometheus, pulling in the stored metrics to create dashboards for easy visualization.
Step-by-Step Setup
1. Install Node Exporter
- Download Node Exporter:
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
- Extract and run Node Exporter:
tar xvfz node_exporter-1.5.0.linux-amd64.tar.gz
cd node_exporter-1.5.0.linux-amd64
./node_exporter
- Access Node Exporter metrics at
http://<your_server_ip>:9100/metrics
.
2. Install Prometheus
- Download Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
- Extract and configure Prometheus:
tar xvfz prometheus-2.45.0.linux-amd64.tar.gz
cd prometheus-2.45.0.linux-amd64
- Edit
prometheus.yml
to add your Node Exporter as a target:
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100'] # Replace with your Node Exporter address
- Start Prometheus:
./prometheus --config.file=prometheus.yml
- Access Prometheus at
http://<your_server_ip>:9090
.
3. Install Grafana
- Download and install Grafana using your package manager:
sudo apt-get install -y grafana # for Debian/Ubuntu
- Start Grafana:
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
- Access Grafana at
http://<your_server_ip>:3000
.
4. Connect Grafana to Prometheus
- Log in to Grafana (default user/password:
admin/admin
). - Go to Configuration > Data Sources and select Prometheus.
- Enter your Prometheus URL (e.g.,
http://localhost:9090
) and save.
5. Create a Dashboard in Grafana
- Go to Dashboards > New Dashboard.
- Choose Add Query and select Prometheus as the data source.
- Enter a metric (e.g.,
node_cpu_seconds_total
), apply, and save the panel.
Conclusion
With this setup, Prometheus will regularly collect metrics from Node Exporter, and Grafana will visualize these metrics. This setup is efficient for monitoring the health and performance of your servers.