简体   繁体   English

SNMP 导出器 (prometheus) + 扩展 OID

[英]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.我是 Prometheus 的新手,我正在尝试监视我使用 snmp_exporter 创建的一些扩展 OID,但它没有按预期工作。

My script just does an "echo $VALUE" (value is an integer or a string).我的脚本只是执行“echo $VALUE”(值是整数或字符串)。

I have this snmpd.conf :我有这个 snmpd.conf :

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

I generated his OID :我生成了他的 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 :现在我可以得到所有的 snmp 扩展链接到我的配置:

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

Now, here is my prometheus configuration prometheus.yml :现在,这是我的 prometheus 配置 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 :和我的 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 :使用该配置,我无法在页面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 :但是,如果我将我的配置放入其他块中,例如 if_mib,我能够获取值但它们被放置在错误的位置: 在此处输入图片说明

As you can see I got the value "1" instead of "6".如您所见,我得到的值是“1”而不是“6”。

I also tried the snmp exporter generator but i'm not able to build it :我还尝试了 snmp 导出器生成器,但无法构建它:

$ 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 .如果您能够更改snmpd.conf ,则意味着您对机器有足够的控制权来运行节点导出器 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.我建议使用节点导出器的文本文件收集器来公开这些数据,而不是花时间弄清楚 SNMP 和 MIB 如何工作的复杂性。

In general you should prefer the Node/WMI exporters where possible over using SNMP.一般来说,与使用 SNMP 相比,您应该尽可能选择 Node/WMI 导出器。

Using the get parameter instead of walk worked for me.使用 get 参数而不是 walk 对我有用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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