Skip to main content

How to install and configure prometheus, grafana and node exporter on ubuntu server


1. Download and install prometheus

Run the following command line for download and install prometheus :

wget https://github.com/prometheus/prometheus/releases/download/v2.37.6/prometheus-2.37.6.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
rm prometheus-*.tar.gz
sudo mkdir /etc/prometheus /var/lib/prometheus
cd prometheus-2.37.6.linux-amd64
sudo mv prometheus promtool /usr/local/bin/
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/
prometheus --version

2. Configure prometheus as a service

Run the following command line for configure prometheus:

sudo useradd -rs /bin/false prometheus
sudo chown -R prometheus: /etc/prometheus /var/lib/prometheus
sudo vi /etc/systemd/system/prometheus.service

Create file /etc/systemd/system/prometheus.service and then fill out it with the following configuration :

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries \
    --web.listen-address=0.0.0.0:9090 \
    --web.enable-lifecycle \
    --log.level=info

[Install]
WantedBy=multi-user.target


and then run the following command line :

sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl start prometheus
sudo systemctl status prometheus

If you want to acces prometheus web dashboard, you can access it via url http://local_ip_addr:9090

3. Install and configure node exporter on client node

Run the following command line on client node
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar xvfz node_exporter-*.tar.gz
sudo mv node_exporter-1.5.0.linux-amd64/node_exporter /usr/local/bin
rm -r node_exporter-1.5.0.linux-amd64*
node_exporter

If you want running node exporter as a service on systemd, you can follow the following step :

sudo useradd -rs /bin/false node_exporter
nano /etc/systemd/system/node_exporter.service

fill out  /etc/systemd/system/node_exporter.service file with the following configuration :

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

and then run the following command line :

sudo systemctl enable node_exporter
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl status node_exporter

4. Configure prometheus for monitoring client node

Edit  /etc/prometheus/prometheus.yml file, and then fill out the following configuration under  scrape_configs word 
- job_name: "remote_collector"
  scrape_interval: 10s
  static_configs:
     - targets: ["remote_addr:9100"]

Run the following command line :

sudo systemctl restart prometheus

5. Install and configure grafana server

You can follow the following step for install grafana server :
sudo apt-get install -y apt-transport-https software-properties-common
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana
sudo systemctl daemon-reload
sudo systemctl enable grafana-server.service
sudo systemctl start grafana-server
sudo systemctl status grafana-server

6. Integration prometheus with grafana

the first, you can login into grafana dashboard  via url http://local_ip_addr:3000 with username:admin and password:admin. and then select Configuration menu --> Data Source --> Add Data Source --> Prometheus. in the URL section you can fill out it with http://localhost:9090. then klik Save & test

7. Import grafana dashboard

If you want to display metrics of each client node on grafana dashboard, you must first import the dashboard. you can follow the following step :
  • Open url Grafana Dashboard Library then type Node Exporter Full
  • Klik Node Exporter Full then press download button
  • Back to grafana dashboard. select menu Dashboard --> Import --> Upload dashboard by pointing to Node Exporter Full dashboard that you just downloaded.

Comments