Preference: https://github.com/prometheus/snmp_exporter
Step 1:
install golang follow https://golang.org/doc/install :
wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz
Extract the archive you downloaded into /usr/local, creating a Go tree in /usr/local/go.
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.3.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
Check Go version:
go version
Step 2:
We need to generate our snmp.yml for cisco devices ( you can check more details at here https://github.com/prometheus/snmp_exporter/tree/main/generator )
Due to the dynamic dependency on NetSNMP, you must build the generator yourself.
sudo apt-get install unzip build-essential libsnmp-dev p7zip-full
go get github.com/prometheus/snmp_exporter/generator
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/snmp_exporter/generator
go buildmake mibs
Add module cisco to generator.yml file before we rendering snmp.yml
i've put my generator.yml on github, replace community: Change_To_Your_Community with your
https://github.com/dhviet/dhv_script/blob/main/dhv_snmp_exporter_generator.yml
Now we can generate our snmp.yml:
export MIBDIRS=mibs
./generator generate
Step 3: Install snmp_exporter
Download snmp_exporter for your platform: https://github.com/prometheus/snmp_exporter/releases
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.20.0/snmp_exporter-0.20.0.linux-amd64.tar.gz
tar -xzvf /home/dhviet/snmp_exporter-0.20.0.linux-amd64.tar.gz
mv /home/dhviet/snmp_exporter-0.20.0.linux-amd64/* /usr/local/snmp_exporter/
Create services for snmp_exporter
vi /etc/systemd/system/snmp_exporter.service
then paste parameters bellow into this file:
[Unit]
Description=Snmp_exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/snmp_exporter/snmp_exporter \
--config.file=/usr/local/snmp_exporter/snmp.yml
[Install]
WantedBy=multi-user.target
Copy new snmp.yml you've generated above to /usr/local/snmp_exporter/
cp /root/go/src/github.com/prometheus/snmp_exporter/generator/snmp.yml /usr/local/snmp_exporter/
Start & enable snmp_exporter services
systemctl start snmp_exporter.service
systemctl enable snmp_exporter.service
systemctl status snmp_exporter.service
Check metric:
access to http://X.X.X.X:9116/ fill your IP target, module: cisco then click submit
vi /etc/prometheus/prometheus.yml
- job_name: '_dhv_snmp'static_configs:- targets: ['X.X.X.X'] # SNMP device.metrics_path: /snmpparams:module: [cisco]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 # The SNMP exporter's real hostname:port.
promtool check config prometheus.ymlsystemctl restart prometheus
At this moment under target on prometheus you should see our new endpoint with status is UP
Open your grafana then select import, for testing i've use grafana dashboard with the id 12489, you can edit by your self or create new one.
No comments:
Post a Comment