Monitoring
Grafana / Prometheus / Node exporter / ...
Node exporter
Installation of node exporter
Download the package from the github repository
cd /tmp
wget <link to the last release>
tar xvfz node_exporter-*.*-amd64.tar.gz
sudo mv node_exporter-*.linux-amd64/node_exporter /usr/local/bin/
chmod +x /usr/local/bin/node_exporter
./node_exporter
Then try to get the metrics with a curl command:
curl http://localhost:9100/metrics
Create a systemctl task
First create a nonlogin user to run the task
sudo useradd -rs /bin/false node_exporter
Create a systemctl file
sudo vim /etc/systemd/system/node_exporter.service
Past the following in it
[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
Then restart the systemctl daemon, start the task and enable it at system start up
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
sudo systemctl status node_exporter
Prometheus
Install Prometheus
First download the source from the web site
wget <link of the source>
tar xvf prometheus-*.*-amd64.tar.gz
mv prometheus-*.*-amd64 prometheus-files
Create an user to run Prometheus and give it the ownership
sudo useradd --no-create-home --shell /bin/false prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
Copy / past the source in the new folder
sudo cp prometheus-files/prometheus /usr/local/bin/
sudo cp prometheus-files/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo cp -r prometheus-files/consoles /etc/prometheus
sudo cp -r prometheus-files/console_libraries /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
Configuration of Prometheus targets
Create a prometheus.yml
to setup the config
sudo vim /etc/prometheus/prometheus.yml
Past it the following and change the target ip:port
global:
scrape_interval: 10s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
Then give the ownership to the user previously created
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
You can now access to the GUI in your browser
http://<prometheus-ip>:9090/graph
Create a systemctl task
Create the systemctl file
sudo vim /etc/systemd/system/prometheus.service
Past it the following
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
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
Restart the systemctl daemon, start the task and enable it at system start up
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus