Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump snmp_exporter to 0.27.0. Add support for multi-module handling #2523

Merged
merged 23 commits into from
Jan 27, 2025

Conversation

v-zhuravlev
Copy link
Contributor

@v-zhuravlev v-zhuravlev commented Jan 24, 2025

PR Description

Bump snmp_exporter to 0.27.0 and adds support for multi-module handling by comma separation:
https://github.com/prometheus/snmp_exporter?tab=readme-ov-file#multi-module-handling

Which issue(s) this PR fixes

Fixes #2438 .

Notes to the Reviewer

I think there should be a better way to define logger that require slog instead of github.com/go-kit/log .(prometheus/snmp_exporter#1249)

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

Example output:

~/repos/grafanalabs/alloy$ curl -k 'http://localhost:12345/api/v0/component/prometheus.exporter.snmp.integrations_snmp/metrics?auth=os.linux.1&module=system,hrSystem&target=127.0.0.1:161'
# HELP hrSystemDate The host's notion of the local date and time of day. - 1.3.6.1.2.1.25.1.2
# TYPE hrSystemDate gauge
hrSystemDate 1.467292973e+09
# HELP hrSystemInitialLoadDevice The index of the hrDeviceEntry for the device from which this host is configured to load its initial operating system configuration (i.e., which operating system code and/or boot parameters) - 1.3.6.1.2.1.25.1.3
# TYPE hrSystemInitialLoadDevice gauge
hrSystemInitialLoadDevice 393216
# HELP hrSystemInitialLoadParameters This object contains the parameters (e.g - 1.3.6.1.2.1.25.1.4
# TYPE hrSystemInitialLoadParameters gauge
hrSystemInitialLoadParameters{hrSystemInitialLoadParameters="0x726F20726F6F743D2F6465762F6D61707065722F76675F736D706D64616F647575722D6C765F726F6F742072645F4E4F5F4C554B53204C414E473D656E5F55532E5554462D382072645F4C564D5F4C563D76675F736D706D64616F647575722F6C765F726F6F742072645F4E4F5F4D4420535953464F4E543D6C617461726379"} 1
# HELP hrSystemMaxProcesses The maximum number of process contexts this system can support - 1.3.6.1.2.1.25.1.7
# TYPE hrSystemMaxProcesses gauge
hrSystemMaxProcesses 0
# HELP hrSystemNumUsers The number of user sessions for which this host is storing state information - 1.3.6.1.2.1.25.1.5
# TYPE hrSystemNumUsers gauge
hrSystemNumUsers 0
# HELP hrSystemProcesses The number of process contexts currently loaded or running on this system. - 1.3.6.1.2.1.25.1.6
# TYPE hrSystemProcesses gauge
hrSystemProcesses 172
# HELP hrSystemUptime The amount of time since this host was last initialized - 1.3.6.1.2.1.25.1.1
# TYPE hrSystemUptime gauge
hrSystemUptime 1.080978091e+09
# HELP snmp_packet_duration_seconds A histogram of latencies for SNMP packets.
# TYPE snmp_packet_duration_seconds histogram
snmp_packet_duration_seconds_bucket{le="0.0001"} 0
snmp_packet_duration_seconds_bucket{le="0.0002"} 0
snmp_packet_duration_seconds_bucket{le="0.0004"} 0
snmp_packet_duration_seconds_bucket{le="0.0008"} 0
snmp_packet_duration_seconds_bucket{le="0.0016"} 0
snmp_packet_duration_seconds_bucket{le="0.0032"} 0
snmp_packet_duration_seconds_bucket{le="0.0064"} 0
snmp_packet_duration_seconds_bucket{le="0.0128"} 0
snmp_packet_duration_seconds_bucket{le="0.0256"} 0
snmp_packet_duration_seconds_bucket{le="0.0512"} 0
snmp_packet_duration_seconds_bucket{le="0.1024"} 0
snmp_packet_duration_seconds_bucket{le="0.2048"} 0
snmp_packet_duration_seconds_bucket{le="0.4096"} 0
snmp_packet_duration_seconds_bucket{le="0.8192"} 0
snmp_packet_duration_seconds_bucket{le="1.6384"} 0
snmp_packet_duration_seconds_bucket{le="+Inf"} 0
snmp_packet_duration_seconds_sum 0
snmp_packet_duration_seconds_count 0
# HELP snmp_packet_retries_total Number of SNMP packet retries.
# TYPE snmp_packet_retries_total counter
snmp_packet_retries_total 0
# HELP snmp_packets_total Number of SNMP packet sent, including retries.
# TYPE snmp_packets_total counter
snmp_packets_total 0
# HELP snmp_request_in_flight Current number of SNMP scrapes being requested.
# TYPE snmp_request_in_flight gauge
snmp_request_in_flight 1
# HELP snmp_scrape_duration_seconds Total SNMP time scrape took (walk and processing).
# TYPE snmp_scrape_duration_seconds gauge
snmp_scrape_duration_seconds{module="hrSystem"} 0.009325017
snmp_scrape_duration_seconds{module="system"} 0.022195107
# HELP snmp_scrape_packets_retried Packets retried for get, bulkget, and walk.
# TYPE snmp_scrape_packets_retried gauge
snmp_scrape_packets_retried{module="hrSystem"} 0
snmp_scrape_packets_retried{module="system"} 0
# HELP snmp_scrape_packets_sent Packets sent for get, bulkget, and walk; including retries.
# TYPE snmp_scrape_packets_sent gauge
snmp_scrape_packets_sent{module="hrSystem"} 1
snmp_scrape_packets_sent{module="system"} 2
# HELP snmp_scrape_pdus_returned PDUs returned from get, bulkget, and walk.
# TYPE snmp_scrape_pdus_returned gauge
snmp_scrape_pdus_returned{module="hrSystem"} 7
snmp_scrape_pdus_returned{module="system"} 31
# HELP snmp_scrape_walk_duration_seconds Time SNMP walk/bulkwalk took.
# TYPE snmp_scrape_walk_duration_seconds gauge
snmp_scrape_walk_duration_seconds{module="hrSystem"} 0.009217207
snmp_scrape_walk_duration_seconds{module="system"} 0.021836451
# HELP snmp_unexpected_pdu_type_total Unexpected Go types in a PDU.
# TYPE snmp_unexpected_pdu_type_total counter
snmp_unexpected_pdu_type_total 0
# HELP sysContact The textual identification of the contact person for this managed node, together with information on how to contact this person - 1.3.6.1.2.1.1.4
# TYPE sysContact gauge
sysContact{sysContact="Monitoring"} 1
# HELP sysDescr A textual description of the entity - 1.3.6.1.2.1.1.1
# TYPE sysDescr gauge
sysDescr{sysDescr="Linux SM-PMDA 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 EDT 2015 x86_64"} 1
# HELP sysLocation The physical location of this node (e.g., 'telephone closet, 3rd floor') - 1.3.6.1.2.1.1.6
# TYPE sysLocation gauge
sysLocation{sysLocation="\"\""} 1
# HELP sysName An administratively-assigned name for this managed node - 1.3.6.1.2.1.1.5
# TYPE sysName gauge
sysName{sysName="SM-PMDA"} 1
# HELP sysORDescr A textual description of the capabilities identified by the corresponding instance of sysORID. - 1.3.6.1.2.1.1.9.1.3
# TYPE sysORDescr gauge
sysORDescr{sysORDescr="The MIB for Message Processing and Dispatching.",sysORIndex="1"} 1
sysORDescr{sysORDescr="The MIB for Message Processing and Dispatching.",sysORIndex="2"} 1
sysORDescr{sysORDescr="The MIB module for SNMPv2 entities",sysORIndex="4"} 1
sysORDescr{sysORDescr="The MIB module for managing IP and ICMP implementations",sysORIndex="6"} 1
sysORDescr{sysORDescr="The MIB module for managing TCP implementations",sysORIndex="5"} 1
sysORDescr{sysORDescr="The MIB module for managing UDP implementations",sysORIndex="7"} 1
sysORDescr{sysORDescr="The SNMP Management Architecture MIB.",sysORIndex="3"} 1
sysORDescr{sysORDescr="View-based Access Control Model for SNMP.",sysORIndex="8"} 1
# HELP sysORID An authoritative identification of a capabilities statement with respect to various MIB modules supported by the local SNMP application acting as a command responder. - 1.3.6.1.2.1.1.9.1.2
# TYPE sysORID gauge
sysORID{sysORDescr="The MIB for Message Processing and Dispatching.",sysORID="1.3.6.1.6.3.11.2.3.1.1",sysORIndex="1"} 1
sysORID{sysORDescr="The MIB for Message Processing and Dispatching.",sysORID="1.3.6.1.6.3.15.2.1.1",sysORIndex="2"} 1
sysORID{sysORDescr="The MIB module for SNMPv2 entities",sysORID="1.3.6.1.6.3.1",sysORIndex="4"} 1
sysORID{sysORDescr="The MIB module for managing IP and ICMP implementations",sysORID="1.3.6.1.2.1.4",sysORIndex="6"} 1
sysORID{sysORDescr="The MIB module for managing TCP implementations",sysORID="1.3.6.1.2.1.49",sysORIndex="5"} 1
sysORID{sysORDescr="The MIB module for managing UDP implementations",sysORID="1.3.6.1.2.1.50",sysORIndex="7"} 1
sysORID{sysORDescr="The SNMP Management Architecture MIB.",sysORID="1.3.6.1.6.3.10.3.1.1",sysORIndex="3"} 1
sysORID{sysORDescr="View-based Access Control Model for SNMP.",sysORID="1.3.6.1.6.3.16.2.2.1",sysORIndex="8"} 1
# HELP sysORLastChange The value of sysUpTime at the time of the most recent change in state or value of any instance of sysORID. - 1.3.6.1.2.1.1.8
# TYPE sysORLastChange gauge
sysORLastChange 3
# HELP sysORUpTime The value of sysUpTime at the time this conceptual row was last instantiated. - 1.3.6.1.2.1.1.9.1.4
# TYPE sysORUpTime gauge
sysORUpTime{sysORDescr="The MIB for Message Processing and Dispatching.",sysORIndex="1"} 3
sysORUpTime{sysORDescr="The MIB for Message Processing and Dispatching.",sysORIndex="2"} 3
sysORUpTime{sysORDescr="The MIB module for SNMPv2 entities",sysORIndex="4"} 3
sysORUpTime{sysORDescr="The MIB module for managing IP and ICMP implementations",sysORIndex="6"} 3
sysORUpTime{sysORDescr="The MIB module for managing TCP implementations",sysORIndex="5"} 3
sysORUpTime{sysORDescr="The MIB module for managing UDP implementations",sysORIndex="7"} 3
sysORUpTime{sysORDescr="The SNMP Management Architecture MIB.",sysORIndex="3"} 3
sysORUpTime{sysORDescr="View-based Access Control Model for SNMP.",sysORIndex="8"} 3
# HELP sysObjectID The vendor's authoritative identification of the network management subsystem contained in the entity - 1.3.6.1.2.1.1.2
# TYPE sysObjectID gauge
sysObjectID{sysObjectID="1.3.6.1.4.1.8072.3.2.10"} 1
# HELP sysUpTime The time (in hundredths of a second) since the network management portion of the system was last re-initialized. - 1.3.6.1.2.1.1.3
# TYPE sysUpTime gauge
sysUpTime 9.34207765e+08

…y comma separation for `prometheus.exporter.snmp`
@v-zhuravlev v-zhuravlev changed the title Bump snmp_exporter to 0.27.0. Add support for multi-module handling b… Bump snmp_exporter to 0.27.0. Add support for multi-module handling Jan 24, 2025
Copy link
Contributor

github-actions bot commented Jan 24, 2025

💻 Deploy preview deleted.

@v-zhuravlev v-zhuravlev marked this pull request as ready for review January 24, 2025 11:00
@v-zhuravlev v-zhuravlev requested review from clayton-cornell and a team as code owners January 24, 2025 11:00
Copy link
Contributor

@wildum wildum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this feature and updating the dependency :)
Do you have a setup to test it? It would be nice to make sure that it works as expected + that the logging still works (it should follow the log level set via the logging block (https://grafana.com/docs/alloy/latest/reference/config-blocks/logging/)). When checking the log level, please ensure that it can also be updated at runtime (change the log level from error to debug, reload the config via "curl localhost:12345/-/reload" and ensure that alloy logs debug lines from the snmp exporter)

go.mod Show resolved Hide resolved
internal/static/integrations/snmp_exporter/snmp.go Outdated Show resolved Hide resolved
internal/static/integrations/snmp_exporter/snmp.go Outdated Show resolved Hide resolved
internal/static/integrations/snmp_exporter/snmp.go Outdated Show resolved Hide resolved
@wildum
Copy link
Contributor

wildum commented Jan 24, 2025

We also have integration tests for the snmp exporter: https://github.com/grafana/alloy/tree/main/internal/cmd/integration-tests/tests/snmp
Maybe you can update it to have more than one module. You can also use the snmp docker image that we use for manual testing if needed

@v-zhuravlev
Copy link
Contributor Author

Thanks for adding this feature and updating the dependency :) Do you have a setup to test it? It would be nice to make sure that it works as expected + that the logging still works (it should follow the log level set via the logging block (https://grafana.com/docs/alloy/latest/reference/config-blocks/logging/)). When checking the log level, please ensure that it can also be updated at runtime (change the log level from error to debug, reload the config via "curl localhost:12345/-/reload" and ensure that alloy logs debug lines from the snmp exporter)

Tested logging, it works now, including reloading:

Here , changed debug to warn:

subcomponent=rw remote_name=672fd3 url=http://192.168.78.8:9090/api/v1/push duration=18.871776538s
ts=2025-01-24T13:41:48.253484256Z level=info msg="reload requested via /-/reload endpoint" service=http
ts=2025-01-24T13:41:48.253917231Z level=info msg="starting complete graph evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2
ts=2025-01-24T13:41:48.254012754Z level=info msg="finished node evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2 node_id=prometheus.exporter.snmp.integrations_snmp duration=60.057µs
ts=2025-01-24T13:41:48.254262735Z level=info msg="finished node evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2 node_id=discovery.relabel.integrations_snmp duration=224.239µs
ts=2025-01-24T13:41:48.25429866Z level=info msg="finished node evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2 node_id=prometheus.exporter.self.alloy_check duration=10.502µs
ts=2025-01-24T13:41:48.254398666Z level=info msg="finished node evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2 node_id=discovery.relabel.alloy_check duration=82.493µs
ts=2025-01-24T13:41:48.2544271Z level=info msg="finished node evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2 node_id=labelstore duration=8.756µs
ts=2025-01-24T13:41:48.254452465Z level=info msg="finished node evaluation" controller_path=/ controller_id="" trace_id=94fc784b8ca8ab4bebf4591f6f1771e2 node_id=tracing duration=9.842µs

@v-zhuravlev
Copy link
Contributor Author

v-zhuravlev commented Jan 24, 2025

Also changed "module" in logging to "module_param" to avoid conflicts with module from snmp_exporter logs:

ts=2025-01-24T13:44:52.94322933Z level=debug msg="Finished scrape" component_path=/ component_id=prometheus.exporter.snmp.integrations_snmp module_param=if_mib,system target=127.0.0.1:161 source_address="" worker=0 module=system duration_seconds=0.025343076

@v-zhuravlev v-zhuravlev requested a review from wildum January 24, 2025 14:10
@wildum
Copy link
Contributor

wildum commented Jan 27, 2025

About the test, it's a tricky one but I actually found out that the defaults are not applied because it's using a custom UnmarshalAlloy function. One way to solve this is to call SetToDefault at the start of this function. It might need to also be called in the config converter if the tests fail there too after the fix

Signed-off-by: Vitaly Zhuravlev <[email protected]>
Signed-off-by: Vitaly Zhuravlev <[email protected]>
Signed-off-by: Vitaly Zhuravlev <[email protected]>
@v-zhuravlev
Copy link
Contributor Author

About the test, it's a tricky one but I actually found out that the defaults are not applied because it's using a custom UnmarshalAlloy function. One way to solve this is to call SetToDefault at the start of this function. It might need to also be called in the config converter if the tests fail there too after the fix

thank you , fixed.

@v-zhuravlev v-zhuravlev requested a review from wildum January 27, 2025 14:16
@wildum wildum merged commit 8d9c4bc into main Jan 27, 2025
30 checks passed
@wildum wildum deleted the vzhuravlev/snmp_exporter_multi_module_handling branch January 27, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

snmp multi module support
2 participants