Skip to content

Commit

Permalink
Bump SNMP exporter to v0.24.1 (#5366)
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc authored Oct 5, 2023
1 parent 8de8dc4 commit 00d2b87
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Main (unreleased)

- Documentation updated to link discovery.http and prometheus.scrape advanced configs (@proffalken)

- Bump SNMP exporter version to v0.23 (@marctc)
- Bump SNMP exporter version to v0.24.1 (@marctc)

- Switch to `IBM/sarama` module. (@hainenber)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ require (
github.com/prometheus/node_exporter v1.6.0
github.com/prometheus/procfs v0.11.1
github.com/prometheus/prometheus v1.99.0
github.com/prometheus/snmp_exporter v0.23.0
github.com/prometheus/snmp_exporter v0.24.1
github.com/prometheus/statsd_exporter v0.22.8
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052
github.com/rs/cors v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,8 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/prometheus/snmp_exporter v0.23.0 h1:v+NUGGSj2a8QaLC4+cWAlTNWoI0qEZ8cEuJmtpVhsew=
github.com/prometheus/snmp_exporter v0.23.0/go.mod h1:vdODeAhHaSbDD2B4yngJgkWkAB393LuCGJUbK8AFfFU=
github.com/prometheus/snmp_exporter v0.24.1 h1:AihTbJHurMo8bjtjJde8U+4gMEvpvYvT21Xbd4SzJgY=
github.com/prometheus/snmp_exporter v0.24.1/go.mod h1:j6uIGkdR0DXvKn7HJtSkeDj//UY0sWmdd6XhvdBjln0=
github.com/prometheus/statsd_exporter v0.22.7/go.mod h1:N/TevpjkIh9ccs6nuzY3jQn9dFqnUakOjnEuMPJJJnI=
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=
Expand Down
15 changes: 12 additions & 3 deletions pkg/integrations/snmp_exporter/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import (
snmp_config "github.com/prometheus/snmp_exporter/config"
)

const (
namespace = "snmp"
// This is the default value for snmp.module-concurrency in snmp_exporter.
// For now we set to 1 as we don't support multi-module handling.
// More info: https://github.com/prometheus/snmp_exporter#multi-module-handling
concurrency = 1
)

type snmpHandler struct {
cfg *Config
snmpCfg *snmp_config.Config
Expand Down Expand Up @@ -79,14 +87,13 @@ func Handler(w http.ResponseWriter, r *http.Request, logger log.Logger, snmpCfg
http.Error(w, "'walk_params' parameter must only be specified once", http.StatusBadRequest)
return
}

if walkParams != "" {
zeroRetries := 0
if wp, ok := wParams[walkParams]; ok {
if wp.MaxRepetitions != 0 {
module.WalkParams.MaxRepetitions = wp.MaxRepetitions
}
if wp.Retries != &zeroRetries {
if wp.Retries != nil && wp.Retries != &zeroRetries {
module.WalkParams.Retries = wp.Retries
}
if wp.Timeout != 0 {
Expand All @@ -100,11 +107,13 @@ func Handler(w http.ResponseWriter, r *http.Request, logger log.Logger, snmpCfg
} else {
logger = log.With(logger, "module", moduleName, "target", target)
}
var nmodules []*collector.NamedModule
nmodules = append(nmodules, collector.NewNamedModule(moduleName, module))
level.Debug(logger).Log("msg", "Starting scrape")

start := time.Now()
registry := prometheus.NewRegistry()
c := collector.New(r.Context(), target, auth, module, logger, registry)
c := collector.New(r.Context(), target, authName, auth, nmodules, logger, NewSNMPMetrics(registry), concurrency)
registry.MustRegister(c)
// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
Expand Down
48 changes: 47 additions & 1 deletion pkg/integrations/snmp_exporter/snmp_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/config"
snmp_common "github.com/grafana/agent/pkg/integrations/snmp_exporter/common"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/snmp_exporter/collector"
snmp_config "github.com/prometheus/snmp_exporter/config"
)

Expand Down Expand Up @@ -97,7 +100,7 @@ func New(log log.Logger, c *Config) (integrations.Integration, error) {
func LoadSNMPConfig(snmpConfigFile string, snmpCfg *snmp_config.Config) (*snmp_config.Config, error) {
var err error
if snmpConfigFile != "" {
snmpCfg, err = snmp_config.LoadFile(snmpConfigFile)
snmpCfg, err = snmp_config.LoadFile([]string{snmpConfigFile})
if err != nil {
return nil, fmt.Errorf("failed to load snmp config from file %v: %w", snmpConfigFile, err)
}
Expand All @@ -112,6 +115,49 @@ func LoadSNMPConfig(snmpConfigFile string, snmpCfg *snmp_config.Config) (*snmp_c
return snmpCfg, nil
}

func NewSNMPMetrics(reg prometheus.Registerer) collector.Metrics {
buckets := prometheus.ExponentialBuckets(0.0001, 2, 15)
return collector.Metrics{
SNMPCollectionDuration: promauto.With(reg).NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Name: "collection_duration_seconds",
Help: "Duration of collections by the SNMP exporter",
},
[]string{"module"},
),
SNMPUnexpectedPduType: promauto.With(reg).NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Name: "unexpected_pdu_type_total",
Help: "Unexpected Go types in a PDU.",
},
),
SNMPDuration: promauto.With(reg).NewHistogram(
prometheus.HistogramOpts{
Namespace: namespace,
Name: "packet_duration_seconds",
Help: "A histogram of latencies for SNMP packets.",
Buckets: buckets,
},
),
SNMPPackets: promauto.With(reg).NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Name: "packets_total",
Help: "Number of SNMP packet sent, including retries.",
},
),
SNMPRetries: promauto.With(reg).NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Name: "packet_retries_total",
Help: "Number of SNMP packet retries.",
},
),
}
}

// Integration is the SNMP integration. The integration scrapes metrics
// from the host Linux-based system.
type Integration struct {
Expand Down

0 comments on commit 00d2b87

Please sign in to comment.