10. Setup Prometheus and Grafana Dashboard

🔮
0. Introduction

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.

🐣
1. Installation

Install prometheus and prometheus node exporter.
1
sudo apt-get install -y prometheus prometheus-alertmanager prometheus-node-exporter
Copied!
Install grafana with su.
1
sudo su
Copied!
1
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
2
echo "deb https://packages.grafana.com/oss/deb stable main" > /etc/apt/sources.list.d/grafana.list
3
sudo apt-get update && sudo apt-get install -y grafana
4
sudo systemctl start grafana-server.service
5
exit
Copied!
Enable services so they start automatically.
1
sudo systemctl enable grafana-server.service
2
sudo systemctl enable prometheus.service
3
sudo systemctl enable prometheus-node-exporter.service
Copied!
To verify that the service has started:
1
sudo systemctl status grafana-server.service
Copied!
1
sudo systemctl status prometheus-node-exporter.service
Copied!
1
sudo systemctl status prometheus.service
Copied!
Update prometheus.yml
1
sudo su
2
cat > /etc/prometheus/prometheus.yml << EOF
3
global:
4
scrape_interval: 15s # By default, scrape targets every 15 seconds.
5
6
# Attach these labels to any time series or alerts when communicating with
7
# external systems (federation, remote storage, Alertmanager).
8
external_labels:
9
monitor: 'codelab-monitor'
10
11
# A scrape configuration containing exactly one endpoint to scrape:
12
# Here it's Prometheus itself.
13
scrape_configs:
14
# The job name is added as a label job=<job_name> to any timeseries scraped from this config.
15
- job_name: 'prometheus'
16
17
static_configs:
18
- targets: ['localhost:9100']
19
EOF
20
exit
Copied!
Finally, restart services.
1
sudo systemctl restart grafana-server.service
2
sudo systemctl restart prometheus.service
3
sudo systemctl restart prometheus-node-exporter.service
Copied!

📶
2. Setting up Grafana Dashboards

  1. 2.
    Login with admin / admin
  2. 3.
    Change password
  3. 4.
    Click the configuration gear icon, then Data Source
  4. 5.
    Select prometheus
  5. 6.
    Set URL to http://localhost:9090
  6. 7.
    Click Save & Test
  7. 8.
    Click Create + icon > Import
  8. 9.
    Add dashboard by importing id: 11074
  9. 10.
    Select Prometheus data source as "Prometheus"
  10. 11.
    Click the Import button.
Grafana dashboard ID 11074 is an excellent overall systems health visualizer.
Grafana dashboard
Congratulations. Prometheus and Grafana are working.