Node Exporter Setup

Posted on: 6/5/2023 Last Updated: 6/5/2023
How to set up Prometheus Node Exporter as a system service
All Articles

Prometheus Node Exporter Setup

for RHEL (RedHat Enterprise Linux) and other systemd based systems

Downloads and Docs

Prometheus Node Exporter guide and Github Download (Source Code and Repo)

Node Exporter Docs

Node Exporter Download

System Binary name for Linux Distros : node_exporter

System Unit File name : node_exporter.service


Setup

Create a directory you want to use. It is handy to put this on a NFS Share that you can mount on your systems so you don't have to copy it to each VM.

This is located in the root directory (/)

Bash (shell command):

mkdir Prometheus_Exporters
cd Prometheus_Exporters

Note: Make sure to copy the node_exporter binary (file you downloaded) into this folder.

Create and edit a System Unit file.

nano node_exporter.service

Add the following:

[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

Now create a basic script to install node_exporter as a named services.

nano quick_setup.sh

and add the following (you will need to make sure this file is "executable". You can use chmod +x quick_setup.sh

#!/bin/bash
# Quick and dirty Prometheus Node Exporter Setup

#############################################################
# Quick vars
#############################################################
        src='/Prometheus_Exporters'
        h=`hostname`


#############################################################
# Confirm Host (whatever goes here if you need it)
#############################################################
echo "Checking details for $h"


#############################################################
# Get the current version from GIT (Use current if you want current dashboards to work!)
#       wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0/node_exporter-1.0.0.linux-amd64.tar.gz
#
# Un-tar it
#       tar -xf node_exporter-1.0.0.linux-amd64.tar.gz
#############################################################



#############################################################
# Copy 'node_exporter' service daemon to /usr/local/bin/
#############################################################
echo "Copying 'node_exporter' to /usr/local/bin/"
        cp ${src}/node_exporter /usr/local/bin/
        ls -hal /usr/local/bin/node_exporter
echo


#############################################################
# Set up a named service account for the 'node_exporter' daemon to run in
#############################################################
echo "Set up a named service account for 'node_exporter'"
        useradd -rs /bin/false node_exporter
        id node_exporter
echo


#############################################################
# Set permissions for the 'node_exporter' service daemon
#############################################################
echo "Set up permissions for the 'node_exporter' service"
        chmod 0755 /usr/local/bin/node_exporter
        chown node_exporter:node_exporter /usr/local/bin/node_exporter
        ls -hal /usr/local/bin/node_exporter
echo


#############################################################
# Create node_exporter.service file
#############################################################
echo "Create a systemd unit file so that node_exporter can be started at boot like a regular system service."
        cp ${src}/node_exporter.service /etc/systemd/system/node_exporter.service
echo


#############################################################
# Have the systemd daemon re-load it's configs (creates sym link)
#############################################################
echo "Since we have created a new unit file, we must reload the systemd daemon"
        systemctl daemon-reload
        cat /etc/systemd/system/node_exporter.service
echo


#############################################################
# Set the service to start on boot and start it now as well
#############################################################
echo "We can set the service to always run at boot and start it"
        systemctl enable node_exporter
        systemctl start node_exporter
        systemctl status node_exporter
echo


#############################################################
# Give it a test!
#############################################################
echo "Give it a test!"
        echo "wget -vvv --no-proxy http://${h}:9100/metrics -O -"
echo
echo

As root (or using sudo) run the setup script. (At your own discretion, and if you follow what I did above)

./quick_setup.sh

It will log each step as it tries to install the service and create a named account for it and start the process etc...

If everything was successful, you should see a wget command to try to hit that new endpoint listening on port :9100 and the metrics are under :9100/metrics

curl could also be used or just your browser. Hope that helps! :)

Tags:
prometheus monitoring doc