Wednesday, April 28, 2021

Prometheus & Grafana - Monitor Cisco Devices use snmp_exporter


 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 build

make 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



Step 4: Add new job for prometheus.yml

vi /etc/prometheus/prometheus.yml
add new job like bellow to this file, replace X.X.X.X with your devices:

- job_name: '_dhv_snmp'
    static_configs:
    - targets: ['X.X.X.X'] # SNMP device.
    metrics_path: /snmp
    params:
      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.
Check then restart prometheus services
promtool check config prometheus.yml
systemctl restart prometheus

At this moment under target on prometheus you should see our new endpoint with status is UP


Step 5: Create Dashboard on Grafana

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

Windows Server 2019 - LAB08 Implementing storage solutions (Part3) Implement Storage Spaces Direct

Part 3:  Implement Storage Spaces Direct What is Storage Spaces Direct? Storage Spaces Direct is the evolution of Storage Spaces . It lever...