Prometheus - SNMP Exporter & Node Exporter
What is SNMP Exporter?
SNMP (Simple Network Management Protocol) Exporter is a tool that allows you to export metrics from devices that support SNMP. SNMP Exporter collects data from SNMP-enabled devices such as routers, switches, servers, and network appliances.
What is Node Exporter?
Node Exporter is a Prometheus exporter specifically designed to collect metrics from Linux and Unix-like systems. It provides detailed information about the system’s hardware and operating system, including CPU usage, memory usage, disk utilization, network statistics, and more.
Topology
As you see above, we’ll have 3 nodes to be collected its data to Prometheus, where 2 of them are Cisco Routers and 1 of them is an Ubuntu server.
Setting up SNMP Exporter
For the Cisco Routers, we’ll utilize the SNMP Exporter to collect its data. SNMP Exporter will be installed on main Prometheus server and it’ll periodically scrapes data to the target hosts.
First, download the SNMP Exporter, and then extract it.
1
2
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.23.0-rc.0/snmp_exporter-0.23.0-rc.0.linux-amd64.tar.gz
tar xvzf snmp_exporter-0.23.0-rc.0.linux-amd64.tar.gz
And then copy the files to its respective directories
1
2
cd snmp_exporter-0.23.0-rc.0.linux-amd64
sudo cp snmp_exporter snmp.yml /usr/local/bin/
Then create the snmp-exporter service file
1
sudo nano /etc/systemd/system/snmp-exporter.service
And this to the file
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Prometheus SNMP Exporter Service
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/snmp_exporter --config.file="/usr/local/bin/snmp.yml"
[Install]
WantedBy=multi-user.target
After that we start the service
1
2
3
systemctl daemon-reload
sudo systemctl start snmp-exporter
sudo systemctl enable snmp-exporter
Check the service status with this command
1
systemctl status snmp-exporter
1
2
3
4
5
6
7
8
9
● snmp-exporter.service - Prometheus SNMP Exporter Service
Loaded: loaded (/etc/systemd/system/snmp-exporter.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2023-07-17 05:19:20 UTC; 2h 36min ago
Main PID: 2258 (snmp_exporter)
Tasks: 14 (limit: 9386)
Memory: 18.4M
CPU: 32.174s
CGroup: /system.slice/snmp-exporter.service
└─2258 /usr/local/bin/snmp_exporter --config.file=/usr/local/bin/snmp.yml
Validate the installation by visiting via browser http://<ip-address:9116>
Next we add the SNMP Exporter into the Prometheus configuration file
1
sudo nano /etc/prometheus/prometheus.yml
Add this at the bottom of the line, you should change the targets IP according to your environment. You should also try playing around with the auth and SNMP module.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- job_name: 'snmp'
static_configs:
- targets:
- 198.18.0.121
- 198.18.0.122 #your network device
metrics_path: /snmp
params:
auth: [public_v2]
module: [if_mib]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116
Run this command to make sure your Prometheus config file is syntactically correct
1
promtool check config /etc/prometheus/prometheus.yml
1
2
Checking /etc/prometheus/prometheus.yml
SUCCESS: /etc/prometheus/prometheus.yml is valid prometheus config file syntax
If all is good, we can proceed to restart Prometheus service.
1
sudo systemctl restart prometheus
Now your SNMP Devices should show up on your Premetheus Targets page.
Setting up Node Exporter
Unlike SNMP Exporter, We’ll be installing Node Exporter directly on the target host. Node Exporter exposes metrics about the system’s hardware and operating system through an HTTP endpoint.
First, let’s create a service user for it
1
sudo useradd --no-create-home --shell /bin/false nodeuser
Then we create a directory for Node Exporter’s configuration, along giving it the right owner.
1
2
sudo mkdir /etc/node_exporter
sudo chown -R nodeuser:nodeuser /etc/node_exporter
Then we’ll download the Node Exporter and extract it.
1
2
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz
tar node_exporter-1.6.0.linux-amd64.tar.gz
Next we copy the file to its appropriate directory and give it a correct owner
1
2
3
cd node_exporter-1.6.0.linux-amd64/
sudo cp node_exporter /usr/local/bin/
sudo chown -R nodeuser:nodeuser /usr/local/bin/node_exporter
After that we create a service file
1
sudo nano /etc/systemd/system/node_exporter.service
and paste this into the file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Node Exporter Service
After=network.target
[Service]
User=nodeuser
Group=nodeuser
Type=simple
ExecStart=/usr/local/bin/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
Then, we start the service by running the following commands
1
2
3
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
Check the status of the service by running this
1
systemctl status node_exporter
1
2
3
4
5
6
7
8
9
10
helena@ubuntu2:~$ systemctl status node_exporter
● node_exporter.service - Node Exporter Service
Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2023-07-17 03:18:21 UTC; 7h ago
Main PID: 17759 (node_exporter)
Tasks: 5 (limit: 4557)
Memory: 8.7M
CPU: 1min 45.941s
CGroup: /system.slice/node_exporter.service
└─17759 /usr/local/bin/node_exporter
Now we jump back to the Prometheus server, and add Node Exporter to the config
1
sudo nano /etc/prometheus/prometheus.yml
And paste this at the bottom of the line. Make sure to change the targets IP according to your environment.
1
2
3
4
5
6
7
8
- job_name: 'node_exporter_client'
scrape_interval: 5s
scheme: http
basic_auth:
username: prom
password: prom
static_configs:
- targets: ['198.18.0.220:9100']
Run this command to make sure the config file is in a correct format
1
promtool check config /etc/prometheus/prometheus.yml
And if it’s all good, restart the Prometheus service.
1
sudo systemctl restart prometheus
Now you should be able to see your Node Exporter target host on Prometheus.
Next, we’ll use Grafana to visualize this data into a visually appealing dashboard.