DEV Community

Pierangelo
Pierangelo

Posted on

Monitoring with Prometheus & Grafana

How set a monitoring system with prometheus, node_exporter and grafana dashboard.

N.B: this tutorial is based on UBUNTU

Prometheus

create prometheus user:

sudo useradd --no-create-home --shell /bin/false prome
Enter fullscreen mode Exit fullscreen mode

create directories

sudo mkdir /etc/prometheus

sudo mkdir /var/lib/prometheus
Enter fullscreen mode Exit fullscreen mode

download prometheus on your server:

wget https://github.com/prometheus/prometheus/releases/download/v2.29.0-rc.1/prometheus-2.29.0-rc.1.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

extract the tar file

tar xvfz prometheus-*.tar.gz
Enter fullscreen mode Exit fullscreen mode

enter in the folder:

cd prometheus-*

Enter fullscreen mode Exit fullscreen mode

edit prometheus.yml

vim prometheus.yml
Enter fullscreen mode Exit fullscreen mode

copy prometheus folder (not the root folder but the folder inside the root folder) in:

sudo cp -rf prometheus /usr/local/bin/

sudo cp -rf promtool /usr/local/bin/
Enter fullscreen mode Exit fullscreen mode

set permission:

sudo chown prome:prome /usr/local/bin/prometheus

sudo chown prome:prome /usr/local/bin/promtool

Enter fullscreen mode Exit fullscreen mode

copy files:

sudo cp -rf consoles /etc/prometheus

sudo cp -rf console_libraries/ /etc/prometheus/
Enter fullscreen mode Exit fullscreen mode

set permissions in /etc

sudo chown -R prome:prome /etc/prometheus/consoles

sudo chown -R prome:prome /etc/prometheus/console_libraries

Enter fullscreen mode Exit fullscreen mode

copy prometheus.yml

sudo cp prometheus.yml /etc/prometheus/prometheus.yml 
Enter fullscreen mode Exit fullscreen mode

start prometheus

./prometheus --config.file=prometheus.yml
Enter fullscreen mode Exit fullscreen mode

create service file:

sudo vim /etc/systemd/system/prometheus.service
Enter fullscreen mode Exit fullscreen mode

and add this code:

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

[Service]
User=prome
Group=prome
Type=simple
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

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

reload daemon

sudo systemctl daemon-reload
Enter fullscreen mode Exit fullscreen mode

system command:

sudo systemctl start prometheus

sudo systemctl enable prometheus

sudo systemctl status prometheus



Enter fullscreen mode Exit fullscreen mode

check:

http://your-machine-ip:9090

node exporter

download node exportyet:

wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

extract:

tar xvfz node_exporter-1.2.2.linux-amd64.tar.gz

Enter fullscreen mode Exit fullscreen mode

enter in the extracted folder:

 cd node_exporter-1.2.2.linux-amd64
Enter fullscreen mode Exit fullscreen mode

run node exportyer

./node_exporter
Enter fullscreen mode Exit fullscreen mode

check metrics on:
http://your-vps-ip:9100

back to prometheus.yml and add ip and port node_exporter

 - job_name: "node exporter test"
    static_configs:
      - targets: ['localhost:9100']

Enter fullscreen mode Exit fullscreen mode

node exporter as service

create user:

sudo useradd -rs /bin/false node_exporter
Enter fullscreen mode Exit fullscreen mode

copy node exporter in bin folder

sudo cp -rf node_exporter-1.2.2.linux-amd64/node_exporter /usr/local/bin
Enter fullscreen mode Exit fullscreen mode

create service file

vim /etc/systemd/system/node_exporter.service
Enter fullscreen mode Exit fullscreen mode
[Unit]
Description=Node Exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

launch sevice commands:

sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
sudo systemctl status node_exporter
Enter fullscreen mode Exit fullscreen mode

grafana

install dependency library:

sudo apt-get install -y adduser libfontconfig1
Enter fullscreen mode Exit fullscreen mode

download deb

wget https://dl.grafana.com/oss/release/grafana_8.1.0_amd64.deb
Enter fullscreen mode Exit fullscreen mode

install:

sudo dpkg -i grafana_8.1.0_amd64.deb
Enter fullscreen mode Exit fullscreen mode

check:

http://your-vps-ip:3000/login

Top comments (0)