Skip to main content

How to Install and Configure Node Exporter on the Client

Before a remote system can be monitored, it must have some type of client to collect the statistics. Several third-party clients are available. However, for ease of use, Prometheus recommends the Node Exporter client. After Node Exporter is installed on a client, the client can be added to the list of servers to scrape in prometheus.yml.

 

Use wget to download this release. The format for the file is https://github.com/prometheus/node_exporter/releases/download/v[release_num]/node_exporter-[release_num].linux-amd64.tar.gz. Replace [release_num] with the number corresponding to the actual release. For example, the following example demonstrates how to download Node Exporter release 1.5.0.

wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz

Extract the application.

tar xvfz node_exporter-*.tar.gz

Move the executable to usr/local/bin so it is accessible throughout the system.

sudo mv node_exporter-1.5.0.linux-amd64/node_exporter /usr/local/bin

(Optional) Remove any remaining files.

rm -r node_exporter-1.5.0.linux-amd64*

There are two ways of running Node Exporter. It can be launched from the terminal using the command node_exporter. Or, it can be activated as a system service. Running it from the terminal is less convenient. But this might not be a problem if the tool is only intended for occasional use. To run Node Exporter manually, use the following command. The terminal outputs details regarding the statistics collection process.

node_exporter

to exit strg+c

It is more convenient to run Node Exporter as a service. To run Node Exporter this way, first, create a node_exporter user.

sudo useradd -rs /bin/false node_exporter

Create a service file for systemctl to use. The file must be named node_exporter.service and should have the following format. Most of the fields are similar to those found in prometheus.service, as described in the previous section.

i use nano for this, vi or else works too.

sudo nano /etc/systemd/system/node_exporter.service


File: /etc/systemd/system/node_exporter.service


[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


(Optional) If you intend to monitor the client on an ongoing basis, use the systemctl enable command to automatically launch Node Exporter at boot time. This continually exposes the system metrics on port 9100. If Node Exporter is only intended for occasional use, do not use the command below.

sudo systemctl enable node_exporter

Reload the systemctl daemon, start Node Exporter, and verify its status. The service should be active.

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

node_exporter.service - Node Exporter
Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-04-11 13:48:06 UTC; 4s ago

 

 

How to Configure Prometheus to Monitor Client Nodes
The client nodes are now ready for monitoring. To add clients to prometheus.yml, follow the steps below:

On the monitoring server running Prometheus, open prometheus.yml for editing.

sudo nano /etc/prometheus/prometheus.yml

Locate the section entitled scrape_configs, which contains a list of jobs. It currently lists a single job named prometheus. This job monitors the local Prometheus task on port 9090. Beneath the prometheus job, add a second job having the job_name of remote_collector. Include the following information.

A scrape_interval of 10s.
Inside static_configs in the targets attribute, add a bracketed list of the IP addresses to monitor. Separate each entry using a comma.
Append the port number :9100 to each IP address.
To enable monitoring of the local server, add an entry for localhost:9100 to the list.
The entry should resemble the following example. Replace remote_addr with the actual IP address of the client.


File: /etc/prometheus/prometheus.yml

- job_name: "remote_collector"
  scrape_interval: 10s
  static_configs:
    - targets: ["remote_addr:9100"]

 

rename the job_name to something like the name of the service that is beeing monitored and the remote_addr to the address of the monitored service.


To immediately refresh Prometheus, restart the prometheus service.

sudo systemctl restart prometheus

 

 

Using a web browser, revisit the Prometheus web portal at port 9090 on the monitoring server. Select Status and then Targets. A second link for the remote_collector job is displayed, leading to port 9100 on the client. Click the link to review the statistics.