September 23, 2022

Grafana (prometheus,node-exporter)

In this article, we will add our servers with nodes to the graphana dashboard, which will allow us to track the load on the hardware

Install node_exporter

We open a session with the server where some node is installed, from where you want to receive data in the dashboard and install the software on this server:

# download 'node_exporter'
sudo apt-get update && sudo apt-get upgrade -y
cd $HOME && \ wget https://github.com/prometheus/node_exporter/releases/download/v1.2.0/node_exporter-1.2.0.linux-amd64.tar.gz && \ tar xvf node_exporter-1.2.0.linux-amd64.tar.gz && \ rm node_exporter-1.2.0.linux-amd64.tar.gz && \ sudo mv node_exporter-1.2.0.linux-amd64 node_exporter && \ chmod +x $HOME/node_exporter/node_exporter && \ mv $HOME/node_exporter/node_exporter /usr/bin && \ rm -Rvf $HOME/node_exporter/

# create a service file 'exporterd'

# create a service file 'exporterd'
sudo tee /etc/systemd/system/exporterd.service > /dev/null <<EOF
[Unit]
Description=node_exporter
After=network-online.target
[Service]
User=$USER
ExecStart=/usr/bin/node_exporter
Restart=always
RestartSec=3
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
#start service exporterd
sudo systemctl daemon-reload \ sudo systemctl enable exporterd \ sudo systemctl restart exporterd

Install prometheus

sudo apt-get update && sudo apt-get upgrade -y
wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz && \ tar xvf prometheus-2.28.1.linux-amd64.tar.gz && \ rm prometheus-2.28.1.linux-amd64.tar.gz && \ mv prometheus-2.28.1.linux-amd64 prometheus

# open the prometheus config for configuration

nano $HOME/prometheus/prometheus.yml

In the tagrets column, after a comma, we need to add the IP address of our server with the node from which the statistics are exported.

Save the changes and create the service.

sudo tee /etc/systemd/system/prometheusd.service > /dev/null <<EOF [Unit] Description=prometheus After=network-online.target [Service] User=$USER ExecStart=$HOME/prometheus/prometheus \ --config.file="$HOME/prometheus/prometheus.yml" Restart=always RestartSec=3 LimitNOFILE=65535 [Install] WantedBy=multi-user.target EOF
# start the 'prometheusd' 
service sudo systemctl daemon-reload && \ sudo systemctl enable prometheusd && \ sudo systemctl restart prometheusd

Install grafana

sudo apt-get install -y adduser libfontconfig1 && \ wget https://dl.grafana.com/oss/release/grafana_8.0.6_amd64.deb && \ sudo dpkg -i grafana_8.0.6_amd64.deb
# start service 'grafana-server' 
sudo systemctl daemon-reload && \
sudo systemctl enable grafana-server && \
sudo systemctl restart grafana-server

We go in the browser on our home device to the address: http://<server_IP>:3000/, where <server_IP> is the IP of the server where prometheus and grafana are installed.

If everything went well, we are greeted by a welcome window grafana:

Login: admin
Password: admin

The next is to add Data Sources. Choosing Prometheus:

Specify in the URL column the address to your server with prometheus :

After click Save & test.

Finally, we need to import the dashboard to see the charts.

I can recommend dashboard with ID: 10242