Prometheus: Prometheus monitoring switch (snmp)

Keywords: Linux github vim yum

Prometheus service is installed by default, service address:

I. obtain snmp information of the switch

snmp service IP (switch IP):

snmp community: dfetest

II. Deploy SNMP exporter

2.1 download SNMP ﹐ exporter

Download the SNMP exporter installation package at: 

After downloading, upload to the / usr/local directory of the machine

Unzip the installation package

#   tar -zvxf snmp_exporter-0.15.0.linux-arm64.tar.gz 
#   mv snmp_exporter-0.15.0.linux-arm64/ snmp_exporter

2.2 configure SNMP ﹐ exporter

The configuration file of SNMP ﹣ exporter needs to be compiled and generated by itself through SNMP Exporter Config Generator project,

Reference method:  

Because Prometheus is developed in go language, the configuration file of SNMP ﹐ exporter compiled by oneself needs go environment. For the installation of go environment in Linux, please refer to: Install go environment section in

After the go environment is installed, build the snmp exporter config Generator and do the following:

#  yum -y install git
#  yum -y install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel
#  go get
#  cd ${GOPATH-$HOME/go}/src/
#  go build
#  make mibs

After compiling, modify the generator.yml file in the current directory. For the configuration of the generator.yml file, please refer to'exporter/tree/master/generator'file-format. The generator.yml file only needs to inject SNMP's community, and only the modules.if'mib.auth field is modified below File Format Consistent with.

#  vim generator.yml

module.if_mib.auth field in generator.yml:

  # Default IF-MIB interfaces table with ifIndex.
    walk: [sysUpTime, interfaces, ifXTable]
    version: 1
      community: dfetest
      - source_indexes: [ifIndex]
        lookup: ifAlias
      - source_indexes: [ifIndex]
        lookup: ifDescr
      - source_indexes: [ifIndex]
        # Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
        lookup: # ifName
        ignore: true # Lookup metric
        ignore: true # Lookup metric
        ignore: true # Lookup metric
        type: EnumAsInfo

After modification, save and exit, and perform the following operations to generate a new snmp.yml file

#   export MIBDIRS=mibs
#   ./generator generate

Replace the newly generated snmp.yml with the snmp.yml in the original SNMP

#   cp snmp.yml /usr/local/snmp_exporter

2.3 verify and set the SNMP ﹣ exporter service to start

#   cd /usr/local/snmp_exporter
#   ./snmp_exporter

Open the service port on 9116, visit in the browser, fill in the IP address of the switch in the Target input box, click the submit button, the data will appear, and the SNMP ﹣ exporter configuration is successful.


2.4 set the SNMP exporter to start in service mode

Ctrl+C ends the SNMP exporter process, creates the SNMP exporter service, and enables the SNMP exporter to power on and start itself as a service.

Add system service

#   vim /etc/systemd/system/snmp_exporter.service

Write the following to a file




Start the service and set the start-up mode

#  systemctl daemon-reload
#  systemctl enable snmp_exporter 
#  systemctl start snmp_exporter

III. modify Prometheus configuration

Enter the installation folder of Prometheus and open the Prometheus configuration file

#  cd /usr/local/prometheus
#  vim prometheus.yml

Add the following to configure monitoring under the "trace" tab. In params.module, you can configure the modules that need to be crawled. If you do not configure them, all the modules will be crawled.

- job_name: 'snmp'
    scrape_interval: 10s
     - targets:
       -  # Switch IP address
    metrics_path: /snmp
    # params:
     # module: [if_mib]
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: # SNMP? Exporter service IP address

Here is the full contents of Prometheus.yml file

# my global config
  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
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
  # 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'.

    - targets: ['localhost:9090']

  - job_name: 'Linux'
    - targets: ['']
        instance: Linux

  - job_name: 'Windows'
    - targets: ['']
        instance: Windows

  - job_name: 'snmp'
    scrape_interval: 10s
     - targets:
       -  # Switch IP address
    metrics_path: /snmp
    # params:
     # module: [if_mib]
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: # SNMP? Exporter service IP address

Save exit, restart Prometheus service

#  systemctl restart prometheus

Browser access View monitoring information

As you can see, snmp has joined in.

IV. configure Grafana

Add dashboard

Grafana officially provides us with many dashboard pages, which can be downloaded and used directly. Browser access Download the required dashboard page

Here we use the snmp monitoring dashboard with the dashboard Id of 10523

Then open our Grafana monitoring page and open the dashboard management page

Click the [import] button

Then copy our dashboard Id (10523) into it

Grafana automatically recognizes the dashboard Id.

Then click the [change] button to generate a random UID, click the input box below, select the data source Prometheus we created earlier, and finally click the [Import] button to complete the Import.

After importing successfully, the Dashboard will be opened automatically, and you can see the snmp monitoring we just set up

Now, the configuration of Prometheus monitoring switch is completed.

Posted by etherboo on Sun, 03 Nov 2019 18:43:14 -0800