简体   繁体   中英

SNMP Exporter (prometheus) + Extend OID

I'm new on Prometheus and i'm trying to monitor some extend OID I created with the snmp_exporter, but it doesn't work as expected.

My script just does an "echo $VALUE" (value is an integer or a string).

I have this snmpd.conf :

extend value-return-test /usr/local/bin/script.sh

I generated his OID :

snmpwalk -v2c -c public localhost NET-SNMP-EXTEND-MIB::nsExtendResult.\"value-return-test\" -On

Now I'm able to get all the snmp extend link to my configuration :

snmpwalk -v2c -c public localhost NET-SNMP-EXTEND-MIB::nsExtendObjects |grep value-return-test

Now, here is my prometheus configuration prometheus.yml :

global:
  scrape_interval: 5s

  - job_name: 'snmp'
    metrics_path: /snmp
    params:
      module: [tests]
    static_configs:
      - targets:
        - 127.0.0.1  # SNMP device - add your IPs here
    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  # SNMP exporter.

and my snmp.yaml :

tests:
  walk:
  - 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.1
  - 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.2
  metrics:
  - name: snmp_test1
    oid: 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.1
    type: DisplayString
    indexes:
    - labelname: ifIndex
      type: Integer32
  - name: snmp_test2
    oid: 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.2
    type: DisplayString
    indexes:
    - labelname: ifIndex
      type: Integer32

With that configuration I'm not able to get my value on the page http://localhost:9116/snmp?target=127.0.0.1&module=tests :

# HELP snmp_scrape_duration_seconds Total SNMP time scrape took (walk and processing).
# TYPE snmp_scrape_duration_seconds gauge
snmp_scrape_duration_seconds 0.004676028
# HELP snmp_scrape_pdus_returned PDUs returned from walk.
# TYPE snmp_scrape_pdus_returned gauge
snmp_scrape_pdus_returned 0
# HELP snmp_scrape_walk_duration_seconds Time SNMP walk/bulkwalk took.
# TYPE snmp_scrape_walk_duration_seconds gauge
snmp_scrape_walk_duration_seconds 0.004477656

However if I put my configuration into an other block like the if_mib, I'm able to get the values BUT they are put in the wrong place : 在此处输入图片说明

As you can see I got the value "1" instead of "6".

I also tried the snmp exporter generator but i'm not able to build it :

$ go build
# github.com/prometheus/snmp_exporter/generator
./net_snmp.go:6:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
compilation terminated.

Thanks for your help

If you are able to change snmpd.conf that implies that you have enough control over the machine to run the node exporter . I'd suggest using the textfile collector of the node exporter to expose this data, rather than spending time figuring out the intricacies of how SNMP and MIBs work.

In general you should prefer the Node/WMI exporters where possible over using SNMP.

Using the get parameter instead of walk worked for me.

tests:
  get:
  - 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.1
  - 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.2
  metrics:
  - name: snmp_test1
    oid: 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.1
    type: DisplayString
    indexes:
    - labelname: ifIndex
      type: Integer32
  - name: snmp_test2
    oid: 1.3.6.1.4.1.8072.1.3.2.4.1.2.23.109.97.105.108.45.113.117.101.117.101.45.115.101.110.100.105.110.103.45.114.97.116.101.2
    type: DisplayString
    indexes:
    - labelname: ifIndex
      type: Integer32

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM