Wednesday, January 19, 2022

Monitor Linux Servers Using Prometheus Node Exporter

 Setup Node Exporter Binary

1. Download the latest node exporter package. You should check the Prometheus downloads section for the latest version and update this command to get that package.




2. Download the node_exporter using wget and untar the file

[root@server1 ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
[root@server1 ~]# tar -xvzf node_exporter-1.3.1.linux-amd64.tar.gz 

3. Move the node export binary to /usr/local/bin

[root@server1 ~]# mv node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/


Create a Custom Node Exporter Service

1. Create a node_exporter user to run the node exporter service.

[root@server1 ~]# useradd -rs /bin/false node_exporter

2. Create a node_exporter service file under systemd.

[root@server1 ~]# vi /etc/systemd/system/node_exporter.service 

3. Add the following service file content to the service file and save 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 

4.  Reload the system daemon and start the node exporter service.

[root@server1 ~]# systemctl daemon-reload
[root@server1 ~]# systemctl start node_exporter

5. Enable the node_exporter service and check the status.

[root@server1 ~]# systemctl enable node_exporter
[root@server1 ~]# systemctl status node_exporter

6. Enable the port 9100/tcp in firewall.

[root@server1 ~]# firewall-cmd --permanent --add-port=9100/tcp
success
[root@server1 ~]# firewall-cmd --reload
success 

7. You can see all the server metrics by visiting your server URL on /metrics as shown below.

http://<server-IP>:9100/metrics


Configure the Server as Target on Prometheus Server

Now that we have the node exporter up and running on the server, we have to add this server as target on the Prometheus server configuration.

Note: This configuration should be done on the Prometheus server.

1. Login to the Prometheus server and open the prometheus.yml file.

[root@promotheus-server ~]# vi /etc/prometheus/prometheus.yml

2. Under the scrape config section add the node exporter target as shown below. Change 192.168.31.252 with your server IP where you have setup node exporter. Job name can be your server hostname or IP for identification purposes.

- job_name: 'node_exporter_metrics'
  scrape_interval: 5s
  static_configs:
    - targets: ['192.168.31.252:9100']

3. Restart the prometheus service for the configuration changes to take place.

[root@promotheus-server ~]# systemctl restart prometheus

4. Now, if you check the target in prometheus web UI (http://<prometheus-IP>:9090/targets) , you will be able to see the status as shown below.


5. Also, you can use the Prometheus expression browser to query for node related metrics. Following are the few key node metrics you can use to find its statistics.

node_memory_MemFree_bytes
node_cpu_seconds_total
node_filesystem_avail_bytes
rate(node_cpu_seconds_total{mode="system"}[1m]) 
rate(node_network_receive_bytes_total[1m])



No comments: