Node Exporter (Prometheus)
Installing Node_Exporter
Downloading The Package
Locate the appropriate package here and copy the URL (should be a Github link) for the below command:
wget LINK_GOES_HERE
Extract the package you downloaded via:
tar xvzf node_exporter-WHATEVER-VERSION-YOU-HAVE.tar.gz
Creating A User
Create a user for node_exporter without a home directory or shell login:
sudo useradd --no-create-home --shell /usr/sbin/nologin node_exporter
Relocating The Files/Directories
From the files extracted, copy the below to '/usr/local/bin/':
sudo cp node_exporter-WHATEVER-VERSION-YOU-HAVE/node_exporter /usr/local/bin/
Change ownership of those files to the node_exporter user:group that we created:
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
Creating Systemd Service File
Creating the Service File
Create a .service file at the below location:
/etc/systemd/system/node_exporter.service
Input the below content into that new .service file:
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter \ # Make sure that each line of the ExecStart block ends in a \ EXCEPT for the final line
--web.listen-address=:PORT # Replace PORT with whatever the desired port number for node_exporter is, 9100 is default if this line is omitted
[Install]
WantedBy=multi-user.target
Starting The Service
Reload the systemd daemons:
sudo systemctl daemon-reload
Start the node_exporter service:
sudo systemctl start node_exporter
Confirm the service started successfully via:
sudo systemctl status node_exporter
If the service is running, enable it so that it starts on every boot:
sudo systemctl enable node_exporter
We can also verify that it's listening/functioning with the below command:
curl http://localhost:PORT/metrics
Updating Prometheus Config
Within the prometheus.yml file, typically located here:
/etc/prometheus/prometheus.yml
Add the following block under the 'scrape_configs:' section:
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:PORT'] # Replace localhost and/or PORT with your actual host and/or PORT number
Reminder that indents, spacing, and punctuation are CRITICAL to get right, and should be in line with the rest of the .yml file
Once the prometheus.yml file has been updated, reload Prometheus via:
curl -X POST http://localhost:PORT/-/reload # Where localhost:PORT are the hostname and port number for Prometheus, NOT the node_exporter
Make sure to verify that this traffic is permissible through any firewalls that may be between any hosts/ports.