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
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Main (unreleased)

- Add livedebugging support for `prometheus.remote_write` (@ravishankar15)

- Bump snmp_exporter and embedded modules to 0.27.0. Add support for multi-module handling by comma separation and expose argument to increase SNMP polling concurrency for `prometheus.exporter.snmp`. (@v-zhuravlev)

v1.6.1
-----------------

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cascade:
ALLOY_RELEASE: v1.7.0
OTEL_VERSION: v0.116.0
PROM_WIN_EXP_VERSION: v0.27.3
SNMP_VERSION: v0.26.0
SNMP_VERSION: v0.27.0
FULL_PRODUCT_NAME: Grafana Alloy
PRODUCT_NAME: Alloy
hero:
Expand Down
2 changes: 1 addition & 1 deletion docs/sources/_index.md.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cascade:
ALLOY_RELEASE: $ALLOY_VERSION
OTEL_VERSION: v0.116.0
PROM_WIN_EXP_VERSION: v0.27.3
SNMP_VERSION: v0.26.0
SNMP_VERSION: v0.27.0
FULL_PRODUCT_NAME: Grafana Alloy
PRODUCT_NAME: Alloy
hero:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Omitted fields take their default values.
| ------------- | -------------------- | ------------------------------------------------ | ------- | -------- |
| `config_file` | `string` | SNMP configuration file defining custom modules. | | no |
| `config` | `string` or `secret` | SNMP configuration as inline string. | | no |
| `concurrency` | `int` | SNMP exporter concurrency. | `1` | no |
| `targets` | `list(map(string))` | SNMP targets. | | no |

The `config_file` argument points to a YAML file defining which snmp_exporter modules to use.
Expand All @@ -61,7 +62,7 @@ The `targets` argument is an alternative to the [target][] block. This is useful
The following labels can be set to a target:
* `name`: The name of the target (required).
* `address` or `__address__`: The address of SNMP device (required).
* `module`: The SNMP module to use for polling.
* `module`: SNMP modules to use for polling, separated by comma.
* `auth`: The SNMP authentication profile to use.
* `walk_params`: The config to use for this target.

Expand All @@ -88,7 +89,7 @@ The `target` block may be specified multiple times to define multiple targets. T
| Name | Type | Description | Default | Required |
|----------------|---------------|-----------------------------------------------------------------------| ------- | -------- |
| `address` | `string` | The address of SNMP device. | | yes |
| `module` | `string` | SNMP module to use for polling. | `""` | no |
| `module` | `string` | SNMP modules to use for polling, separated by comma. | `""` | no |
| `auth` | `string` | SNMP authentication profile to use. | `""` | no |
| `walk_params` | `string` | Config to use for this target. | `""` | no |
| `snmp_context` | `string` | Override the `context_name` parameter in the SNMP configuration file. | `""` | no |
Expand Down Expand Up @@ -138,7 +139,7 @@ prometheus.exporter.snmp "example" {

target "network_switch_1" {
address = "192.168.1.2"
module = "if_mib"
module = "system,if_mib"
walk_params = "public"
labels = {
"env" = "dev",
Expand All @@ -147,7 +148,7 @@ prometheus.exporter.snmp "example" {

target "network_router_2" {
address = "192.168.1.3"
module = "mikrotik"
module = "system,if_mib,mikrotik"
walk_params = "private"
}

Expand Down Expand Up @@ -180,13 +181,13 @@ prometheus.exporter.snmp "example" {

target "network_switch_1" {
address = "192.168.1.2"
module = "if_mib"
module = "system,if_mib"
walk_params = "public"
}

target "network_router_2" {
address = "192.168.1.3"
module = "mikrotik"
module = "system,if_mib,mikrotik"
walk_params = "private"
}

Expand Down Expand Up @@ -232,14 +233,14 @@ prometheus.exporter.snmp "example" {
{
"name" = "network_switch_1",
"address" = "192.168.1.2",
"module" = "if_mib",
"module" = "system,if_mib",
"walk_params" = "public",
"env" = "dev",
},
{
"name" = "network_router_2",
"address" = "192.168.1.3",
"module" = "mikrotik",
"module" = "system,if_mib,mikrotik",
"walk_params" = "private",
},
]
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ require (
github.com/prometheus/node_exporter v1.6.0
github.com/prometheus/procfs v0.15.1
github.com/prometheus/prometheus v0.55.1 // a.k.a. v2.51.2
github.com/prometheus/snmp_exporter v0.26.0 // if you update the snmp_exporter version, make sure to update the SNMP_VERSION in _index
github.com/prometheus/snmp_exporter v0.27.0 // if you update the snmp_exporter version, make sure to update the SNMP_VERSION in _index
wildum marked this conversation as resolved.
Show resolved Hide resolved
github.com/prometheus/statsd_exporter v0.22.8
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052
github.com/rogpeppe/go-internal v1.13.1
Expand Down Expand Up @@ -541,7 +541,7 @@ require (
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/gophercloud/gophercloud v1.13.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosnmp/gosnmp v1.37.0 // indirect
github.com/gosnmp/gosnmp v1.38.0 // indirect
github.com/grafana/go-offsets-tracker v0.1.7 // indirect
github.com/grafana/gomemcache v0.0.0-20231204155601-7de47a8c3cb0 // indirect
github.com/grafana/jfr-parser v0.9.2 // indirect
Expand Down Expand Up @@ -709,7 +709,7 @@ require (
github.com/prometheus-community/go-runit v0.1.0 // indirect
github.com/prometheus-community/prom-label-proxy v0.6.0 // indirect
github.com/prometheus/alertmanager v0.27.0 // indirect
github.com/prometheus/exporter-toolkit v0.13.1 // indirect
github.com/prometheus/exporter-toolkit v0.13.2 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/relvacode/iso8601 v1.6.0 // indirect
github.com/remeh/sizedwaitgroup v1.0.0 // indirect
Expand Down Expand Up @@ -882,6 +882,7 @@ require (
github.com/containerd/typeurl/v2 v2.2.0 // indirect
github.com/containers/common v0.61.0 // indirect
github.com/deneonet/benc v1.1.2 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/onsi/ginkgo/v2 v2.21.0 // indirect
github.com/onsi/gomega v1.35.1 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosnmp/gosnmp v1.37.0 h1:/Tf8D3b9wrnNuf/SfbvO+44mPrjVphBhRtcGg22V07Y=
github.com/gosnmp/gosnmp v1.37.0/go.mod h1:GDH9vNqpsD7f2HvZhKs5dlqSEcAS6s6Qp099oZRCR+M=
github.com/gosnmp/gosnmp v1.38.0 h1:I5ZOMR8kb0DXAFg/88ACurnuwGwYkXWq3eLpJPHMEYc=
github.com/gosnmp/gosnmp v1.38.0/go.mod h1:FE+PEZvKrFz9afP9ii1W3cprXuVZ17ypCcyyfYuu5LY=
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
github.com/grafana/alloy-remote-config v0.0.9 h1:gy34SxZ8Iq/HrDTIFZi80+8BlT+FnJhKiP9mryHNEUE=
github.com/grafana/alloy-remote-config v0.0.9/go.mod h1:kHE1usYo2WAVCikQkIXuoG1Clz8BSdiz3kF+DZSCQ4k=
Expand Down Expand Up @@ -2169,6 +2171,8 @@ github.com/influxdata/toml v0.0.0-20190415235208-270119a8ce65/go.mod h1:zApaNFpP
github.com/influxdata/wlog v0.0.0-20160411224016-7c63b0a71ef8/go.mod h1:/2NMgWB1DHM1ti/gqhOlg+LJeBVk6FqR5aVGYY0hlwI=
github.com/ionos-cloud/sdk-go/v6 v6.1.11 h1:J/uRN4UWO3wCyGOeDdMKv8LWRzKu6UIkLEaes38Kzh8=
github.com/ionos-cloud/sdk-go/v6 v6.1.11/go.mod h1:EzEgRIDxBELvfoa/uBN0kOQaqovLjUWEB7iW4/Q+t4k=
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
Expand Down Expand Up @@ -2945,8 +2949,8 @@ github.com/prometheus/memcached_exporter v0.13.0 h1:d246RYODFCXy39XA8S2PBrqp5jLC
github.com/prometheus/memcached_exporter v0.13.0/go.mod h1:fp7Wk6v0RFijeP3Syvd1TShBSJoCG5iFfvPdi5dCMEU=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/prometheus/snmp_exporter v0.26.0 h1:7THSh/mAIMmHkiVhmsrAwiH1XNGiFelhPCKBe8PXg8U=
github.com/prometheus/snmp_exporter v0.26.0/go.mod h1:GJEhIONojqxbjn3eyCykWeGVXQJg9pdYSX2scFLpEA0=
github.com/prometheus/snmp_exporter v0.27.0 h1:ZQDMq/bXZnl6azn6EhZg6YTX8+Bzwm520Wg0KNJG8J8=
github.com/prometheus/snmp_exporter v0.27.0/go.mod h1:rxdBALtsEnTVlnvdgUKvCTrs6cS35W3NGlxKEumK3Ww=
github.com/prometheus/statsd_exporter v0.22.8 h1:Qo2D9ZzaQG+id9i5NYNGmbf1aa/KxKbB9aKfMS+Yib0=
github.com/prometheus/statsd_exporter v0.22.8/go.mod h1:/DzwbTEaFTE0Ojz5PqcSk6+PFHOPWGxdXVr6yC8eFOM=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
Expand Down
68 changes: 64 additions & 4 deletions internal/cmd/integration-tests/tests/snmp/config.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ prometheus.remote_write "snmp_metrics" {
}
queue_config {
max_samples_per_send = 100
}
}
}
external_labels = {
test_name = "snmp_metrics",
}
}
}

prometheus.exporter.snmp "snmp_metrics2" {
Expand Down Expand Up @@ -92,10 +92,70 @@ prometheus.remote_write "snmp_metrics2" {
}
queue_config {
max_samples_per_send = 100
}
}
}
external_labels = {
test_name = "snmp_metrics2",
}
}
}

prometheus.exporter.snmp "snmp_metrics3" {
wildum marked this conversation as resolved.
Show resolved Hide resolved
config = `
auths:
public_v2:
community: public
security_level: noAuthNoPriv
auth_protocol: MD5
priv_protocol: DES
version: 2
modules:
default:
walk:
- 1.3.6.1.2.1.1 # OID for system
- 1.3.6.1.2.1.2 # OID for interfaces
metrics:
- name: sysDescr
oid: 1.3.6.1.2.1.1.1.0
type: DisplayString
help: "A textual description of the entity."
hrDevice:
walk:
- 1.3.6.1.2.1.25.3
metrics:
- name: hrDeviceIndex
oid: 1.3.6.1.2.1.25.3.2.1.1
type: gauge
help: A unique value for each device contained by the host - 1.3.6.1.2.1.25.3.2.1.1
indexes:
- labelname: hrDeviceIndex
type: gauge
`
target "t1" {
address = "localhost:161"
module = "default,hrDevice"
auth = "public_v2"
}
}

prometheus.scrape "snmp_metrics3" {
targets = prometheus.exporter.snmp.snmp_metrics3.targets
forward_to = [prometheus.remote_write.snmp_metrics3.receiver]
scrape_interval = "1s"
scrape_timeout = "500ms"
}

prometheus.remote_write "snmp_metrics3" {
endpoint {
url = "http://localhost:9009/api/v1/push"
metadata_config {
send_interval = "1s"
}
queue_config {
max_samples_per_send = 100
}
}
external_labels = {
test_name = "snmp_metrics3",
}
}

22 changes: 22 additions & 0 deletions internal/cmd/integration-tests/tests/snmp/snmp_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ func TestSNMPMetrics(t *testing.T) {
"sysDescr",
"up",
}
var SNMPMetrics3 = []string{
"scrape_duration_seconds",
"scrape_samples_post_metric_relabeling",
"scrape_samples_scraped",
"scrape_series_added",
"snmp_packet_duration_seconds_bucket",
"snmp_packet_duration_seconds_count",
"snmp_packet_duration_seconds_sum",
"snmp_packet_retries_total",
"snmp_packets_total",
"snmp_request_in_flight",
"snmp_scrape_duration_seconds",
"snmp_scrape_packets_retried",
"snmp_scrape_packets_sent",
"snmp_scrape_pdus_returned",
"snmp_scrape_walk_duration_seconds",
"snmp_unexpected_pdu_type_total",
"sysDescr",
"hrDeviceIndex",
"up",
}
common.MimirMetricsTest(t, SNMPMetrics, []string{}, "snmp_metrics")
common.MimirMetricsTest(t, SNMPMetrics, []string{}, "snmp_metrics2")
common.MimirMetricsTest(t, SNMPMetrics3, []string{}, "snmp_metrics3")
}
31 changes: 22 additions & 9 deletions internal/component/prometheus/exporter/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,24 @@ func (w WalkParams) Convert() map[string]snmp_config.WalkParams {
return walkParams
}

// DefaultArguments holds non-zero default options for Arguments when it is
// unmarshaled from Alloy.
var DefaultArguments = Arguments{
SnmpConcurrency: 1,
}

// SetToDefault implements syntax.Defaulter.
func (a *Arguments) SetToDefault() {
*a = DefaultArguments
}

type Arguments struct {
ConfigFile string `alloy:"config_file,attr,optional"`
Config alloytypes.OptionalSecret `alloy:"config,attr,optional"`
Targets TargetBlock `alloy:"target,block,optional"`
WalkParams WalkParams `alloy:"walk_param,block,optional"`
ConfigStruct snmp_config.Config
ConfigFile string `alloy:"config_file,attr,optional"`
SnmpConcurrency int `alloy:"concurrency,attr,optional"`
Config alloytypes.OptionalSecret `alloy:"config,attr,optional"`
Targets TargetBlock `alloy:"target,block,optional"`
WalkParams WalkParams `alloy:"walk_param,block,optional"`
ConfigStruct snmp_config.Config

// New way of passing targets. This allows the component to receive targets from other components.
TargetsList TargetsList `alloy:"targets,attr,optional"`
Expand Down Expand Up @@ -233,10 +245,11 @@ func (a *Arguments) Convert() *snmp_exporter.Config {
targets = a.TargetsList.Convert()
}
return &snmp_exporter.Config{
SnmpConfigFile: a.ConfigFile,
SnmpTargets: targets,
WalkParams: a.WalkParams.Convert(),
SnmpConfig: a.ConfigStruct,
SnmpConfigFile: a.ConfigFile,
SnmpConcurrency: a.SnmpConcurrency,
SnmpTargets: targets,
WalkParams: a.WalkParams.Convert(),
SnmpConfig: a.ConfigStruct,
}
}

Expand Down
7 changes: 5 additions & 2 deletions internal/component/prometheus/exporter/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func TestUnmarshalAlloy(t *testing.T) {
alloyCfg := `
config_file = "modules.yml"
concurrency = 2
target "network_switch_1" {
address = "192.168.1.2"
module = "if_mib"
Expand All @@ -25,7 +26,7 @@ func TestUnmarshalAlloy(t *testing.T) {
}
target "network_router_2" {
address = "192.168.1.3"
module = "mikrotik"
module = "system,mikrotik"
walk_params = "private"
}
walk_param "private" {
Expand All @@ -38,6 +39,7 @@ func TestUnmarshalAlloy(t *testing.T) {
var args Arguments
err := syntax.Unmarshal([]byte(alloyCfg), &args)
require.NoError(t, err)
require.Equal(t, 2, args.SnmpConcurrency)
require.Equal(t, "modules.yml", args.ConfigFile)
require.Equal(t, 2, len(args.Targets))

Expand All @@ -50,7 +52,7 @@ func TestUnmarshalAlloy(t *testing.T) {

require.Contains(t, "network_router_2", args.Targets[1].Name)
require.Contains(t, "192.168.1.3", args.Targets[1].Target)
require.Contains(t, "mikrotik", args.Targets[1].Module)
require.Contains(t, "system,mikrotik", args.Targets[1].Module)
require.Contains(t, "private", args.Targets[1].WalkParams)
require.Empty(t, args.Targets[1].Auth)

Expand Down Expand Up @@ -90,6 +92,7 @@ func TestUnmarshalAlloyTargets(t *testing.T) {
var args Arguments
err := syntax.Unmarshal([]byte(alloyCfg), &args)
require.NoError(t, err)
require.Equal(t, 1, args.SnmpConcurrency)
require.Equal(t, "modules.yml", args.ConfigFile)
require.Equal(t, 2, len(args.TargetsList))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ prometheus.scrape "integrations_blackbox" {
}

prometheus.exporter.snmp "integrations_snmp" {
concurrency = 1
targets = [{
address = "192.168.1.2",
auth = "public",
Expand All @@ -721,7 +722,7 @@ prometheus.exporter.snmp "integrations_snmp" {
}, {
address = "192.168.1.3",
auth = "private",
module = "mikrotik",
module = "system,mikrotik",
name = "network_router_2",
snmp_context = "dummyContext",
walk_params = "private",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ integrations:
snmp_context: dummyContext
- name: network_router_2
address: 192.168.1.3
module: mikrotik
module: system,mikrotik
walk_params: private
auth: private
snmp_context: dummyContext
Expand Down
Loading
Loading