10. Setup Prometheus and Grafana Dashboard
Prometheus is a monitoring platform that collects metrics from monitored targets by scraping metrics HTTP endpoints on these targets. Official documentation is available here. Grafana is a dashboard used to visualize the collected data.
Install prometheus and prometheus node exporter.
sudo apt-get install -y prometheus prometheus-alertmanager prometheus-node-exporter
Install grafana with su.
sudo su
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" > /etc/apt/sources.list.d/grafana.list
sudo apt-get update && sudo apt-get install -y grafana
sudo systemctl start grafana-server.service
exit
Enable services so they start automatically.
sudo systemctl enable grafana-server.service
sudo systemctl enable prometheus.service
sudo systemctl enable prometheus-node-exporter.service
To verify that the service has started:
sudo systemctl status grafana-server.service
sudo systemctl status prometheus-node-exporter.service
sudo systemctl status prometheus.service
Update prometheus.yml
sudo su
cat > /etc/prometheus/prometheus.yml << EOF
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label job=<job_name> to any timeseries scraped from this config.
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9100']
EOF
exit
Finally, restart services.
sudo systemctl restart grafana-server.service
sudo systemctl restart prometheus.service
sudo systemctl restart prometheus-node-exporter.service
- 1.
- 2.Login with admin / admin
- 3.Change password
- 4.Click the configuration gear icon, then Data Source
- 5.Select prometheus
- 6.Set URL to http://localhost:9090
- 7.Click Save & Test
- 8.Click Create + icon > Import
- 9.Add dashboard by importing id: 11074
- 10.Select Prometheus data source as "Prometheus"
- 11.Click the Import button.

Grafana dashboard
Congratulations. Prometheus and Grafana are working.
Last modified 2yr ago