Prometheus – Ubuntu Node Exporter Install
This is to install the node exporter on a raspberry pi for Prometheus to scrap.
Step1: Download
Install the node exporter for Prometheus on your Raspberry Pi
You will need to look at here for the current version of the node exporter from github
https://github.com/prometheus/node_exporter/releases Step2: Install
Log into your Redhat Server
Once you have the latest located from step 1 then right click on it to get the link copied in your clipboard, for this example we are using 1.91 version
wget https://github.com/prometheus/node_exporter/releases/download/v1.12.1/node_exporter-1.12.1.linux-amd64.tar.gz Now un-tar the release using this command.
tar -xvzf node_exporter-1.12.1.linux-amd64.tar.gz This will un-tar the files into a sub-directory that looks like this.
| node_exporter-1.12.1.linux-armv7/ node_exporter-1.12.1.linux-armv7/node_exporter node_exporter-1.12.1.linux-armv7/LICENSE node_exporter-1.12.1.linux-armv7/NOTICE |
The only file we need out of the expanded tarball is the node_exporter binary. Copy that file to /usr/local/bin.
sudo cp node_exporter-1.12.1.linux-amd64/node_exporter /usr/local/bin Use the chmod command to make the node_exporter binary executable.
sudo chmod +x /usr/local/bin/node_exporter Step 3 – Setup systemd unit file
Next step, setting up the unit file. The unit file will allow us to control the service via the systemctl command. Additionally it will ensure node_exporter starts on boot.
Create a file called node_exporter.service in the /etc/sytemd/system directory. The full path to the file should be:
sudo vi /etc/systemd/system/node_exporter.service Put the following contents into the file:
[Unit] Description=Node Exporter Wants=network-online.target After=network-online.target [Service] #User=pi # Or the user you want to run it as, or leave commented out for default ExecStart=/usr/local/bin/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target Now lets reload systemd, enable and start the service.
sudo systemctl daemon-reload sudo systemctl enable node_exporter.service sudo systemctl start node_exporter.service sudo systemctl status node_exporter Step4: Test
You can test if the setup works this way as well
curl http://localhost:9100 Next steps on Prometheus
Now you should add the metrics endpoint as a target to your Prometheus server. You can do this by editing the prometheus configuration file on your prometheus server. For reference mine looks like this.
# my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] - job_name: 'raspberry_pi' scrape_interval: 5s static_configs: - targets: ['pi1.sflservicesllc.com::9100','pi2.sflservicesllc.com:9100'] This is the standard prometheus config file. However I added the following target at the end for my Raspberry Pi:
- job_name: 'pi1' scrape_interval: 5s static_configs: - targets: ['pi1.sflservicesllc.com::9100'] The IP address of my Raspberry Pi is 10.1.100.2. The Port 9100 corresponds is the port used by node_exporter.
Restart Prometheus server to start scrapping