Node Exporter stands out as the optimal solution for aggregating Linux server metrics and statistics, providing a robust monitoring framework.
Monitoring Linux Servers Using Prometheus
This guide outlines the process of setting up Prometheus Node Exporter on a Linux server to export comprehensive node-level metrics to the Prometheus server.
Before You Begin
Ensure that the Prometheus server is operational. If you need assistance with Prometheus setup, refer to the Prometheus setup guide for Linux. Additionally, open port 9100 in the server firewall, as Prometheus reads metrics on this port.
Setting Up Node Exporter Binary
Step 1: Download the latest Node Exporter package. Adjust the command based on the latest version available on the Prometheus downloads section.
cd /tmp
curl -LO https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
Step 2: Unpack the tarball.
tar -xvf node_exporter-0.18.1.linux-amd64.tar.gz
Step 3: Move the Node Exporter binary to /usr/local/bin/.
sudo mv node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/
Creating a Custom Node Exporter Service
Step 1: Create a node_exporter user to run the Node Exporter service.
sudo useradd -rs /bin/false node_exporter
Step 2: Create a Node Exporter service file under systemd.
sudo vi /etc/systemd/system/node_exporter.service
Step 3: Add the following 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
Step 4: Reload the system daemon and start the Node Exporter service.
sudo systemctl daemon-reload
sudo systemctl start node_exporter
Step 5: Check the Node Exporter status to ensure it is running actively.
sudo systemctl status node_exporter
Step 6: Enable the Node Exporter service for system startup.
sudo systemctl enable node_exporter
Now, Node Exporter is exporting metrics on port 9100. View all server metrics by visiting your server URL on /metrics.
Configuring the Server as a Target on Prometheus Server
Now that Node Exporter is operational on the server, add this server as a target in the Prometheus server configuration.
Note: Perform this configuration on the Prometheus server.
Step 1: Log in to the Prometheus server and open the prometheus.yml file.
sudo vi /etc/prometheus/prometheus.yml
Step 2: Under the scrape config section, add the Node Exporter target as shown below. Replace '10.142.0.3' with your server IP where Node Exporter is set up. The job name can be your server hostname or IP for identification purposes.
- job_name: 'node_exporter_metrics'
scrape_interval: 5s
static_configs:
- targets: ['10.142.0.3:9100']
Step 3: Restart the Prometheus service for the configuration changes to take effect.
sudo systemctl restart prometheus
Now, checking the target in the Prometheus web UI (http://<prometheus-IP>:9090/targets) will display the status of Node Exporter.
You can also utilize the Prometheus expression browser to query node-related metrics. Key metrics include node_memory_MemFree_bytes, node_cpu_seconds_total, node_filesystem_avail_bytes, rate(node_cpu_seconds_total{mode="system"}[1m]), and rate(node_network_receive_bytes_total[1m]).
Follow the "Integrate And Visualize Prometheus Metrics In Grafana" blog to visualize Node Exporter metrics in Grafana.
Add new comment