Prometheus: Node Exporter – Install and Config – Ubuntu, CentOS

What is Node Exporter? Node Exporter is a Prometheus exporter for hardware and OS metrics with pluggable metric collectors.

It allows to measure various machine resources such as memory, disk and CPU utilization.

In this article I’ll show how to install and configure Node Exporter on Ubuntu and CentOS using a systemd service manager.

Cool Tip: Install Prometheus using Docker on Ubuntu and CentOS! Read More →

Node Exporter: Install and Config

Create unprivileged node_exporter user:

$ sudo useradd node_exporter -s /sbin/nologin

Check the download page for the latest compiled binary of the Node Exporter and download it:

$ wget https://github.com/prometheus/node_exporter/releases/download/v*/node_exporter-*.*-amd64.tar.gz
$ tar xvfz node_exporter-*.*-amd64.tar.gz
$ sudo cp node_exporter-*.*-amd64/node_exporter /usr/sbin/

Create a systemd service file /etc/systemd/system/node_exporter.service:

[Unit]
Description=Node Exporter

[Service]
User=node_exporter
EnvironmentFile=/etc/sysconfig/node_exporter
ExecStart=/usr/sbin/node_exporter $OPTIONS

[Install]
WantedBy=multi-user.target

Create a sysconfig file:

$ sudo mkdir -p /etc/sysconfig
$ sudo touch /etc/sysconfig/node_exporter

Use this file to define options to provide, for example:

OPTIONS="--collector.textfile.directory /var/lib/node_exporter/textfile_collector"

To check the all available options, run:

$ /usr/sbin/node_exporter --help

Reload systemd configuration and configure node_exporter to auto-start on system boot:

$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter

Start the node_exporter service:

$ sudo systemctl start node_exporter

Once the Node Exporter is installed, verify that metrics are being exported:

$ curl http://localhost:9100/metrics

Add Node Exporter Target to Prometheus

Now all that’s left is to tell Prometheus server about the new target.

This needs to be done in the Prometheus config, as Node Exporter just exposes metrics and Prometheus pulls them from the targets it knows about.

Open your Prometheus config file prometheus.yml, and add your machine to the scrape_configs section as follows:

scrape_configs:
  - job_name: 'node'
    static_configs:
      - targets: ['$NODE_IP:9100']

Reload the Prometheus config, and you should now be able to access your server’s metrics through Prometheus!