Prometheus新手求助:SNMP Exporter监控自定义扩展OID异常
Hey there! Let's work through getting your custom extend OID properly monitored with Prometheus. It sounds like you've got the basics set up, but there are a few common snags that might be tripping you up. Let's break this down step by step:
1. Double-Check You're Targeting the Right OID
First off—you might be scraping the wrong metric from the NET-SNMP-EXTEND-MIB. The nsExtendResult OID you're checking is actually the exit code of your script (0 for success, non-zero for errors), not the output of your echo $VALUE command.
To get the actual output from your script, you need to target nsExtendOutputFull instead. Run this command to find its OID:
snmpwalk -v2c -c public localhost NET-SNMP-EXTEND-MIB::nsExtendOutputFull."value-return-test" -On
That's the OID you should be configuring in SNMP Exporter, not the result code.
2. Configure SNMP Exporter to Scrape the Correct Metric
Update your snmp.yml configuration file to include a module for your custom extend OID. Replace the example OID below with the one you got from the nsExtendOutputFull snmpwalk:
modules: custom_value_return: walk: - .1.3.6.1.4.1.8072.1.3.2.4.1.2.16.118.97.108.117.101.45.114.101.116.117.114.110.45.116.101.115.114 metrics: - name: value_return_test_output oid: .1.3.6.1.4.1.8072.1.3.2.4.1.2.16.118.97.108.117.101.45.114.101.116.117.114.110.45.116.101.115.114 type: gauge # Use "string" if your output is text, but Prometheus handles numeric metrics better help: "Output from custom value-return-test script"
Restart the SNMP Exporter service after making this change.
3. Verify SNMP Exporter Can Fetch the Metric
Test if the SNMP Exporter is correctly pulling the metric by running this curl command (replace <snmp-exporter-ip> with your exporter's IP or use localhost if it's on the same machine):
curl http://<snmp-exporter-ip>:9116/snmp?target=localhost&module=custom_value_return
Look through the output for the value_return_test_output metric. If it shows up with your expected value, great—move on to checking Prometheus. If not, double-check your OID in snmp.yml and make sure the SNMP Exporter can reach the snmpd service.
4. Ensure Your Script Works for the SNMP User
The snmpd daemon runs as the snmp user by default, so you need to make sure this user can execute your script and that the script outputs the correct value.
- Set proper permissions on your script:
chmod +x /usr/local/bin/script.sh chown snmp:snmp /usr/local/bin/script.sh - Test running the script as the
snmpuser:su - snmp -s /bin/bash -c "/usr/local/bin/script.sh"
If this doesn't output your expected $VALUE, fix the script's logic or permissions before proceeding.
5. Update Prometheus to Scrape the New Metric
Add a scrape job to your prometheus.yml to pull metrics from the SNMP Exporter's custom module:
scrape_configs: - job_name: 'snmp_custom_extend' static_configs: - targets: ['<snmp-exporter-ip>:9116'] params: module: ['custom_value_return']
Restart Prometheus, then head to the Prometheus UI and search for value_return_test_output—you should see your metric data there.
内容的提问来源于stack exchange,提问作者Skullone

