From 63d7117547325dfda4e0a863adb5da240b81c89d Mon Sep 17 00:00:00 2001 From: Kakuya Ando Date: Wed, 21 Feb 2024 15:34:43 +0900 Subject: [PATCH] Add SNMPInflight metric (#1119) * Add SNMPInflight metric --------- Signed-off-by: Kakuya Ando --- collector/collector.go | 3 +++ main.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/collector/collector.go b/collector/collector.go index cb1faed0..1b7337ac 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -275,6 +275,7 @@ type Metrics struct { SNMPDuration prometheus.Histogram SNMPPackets prometheus.Counter SNMPRetries prometheus.Counter + SNMPInflight prometheus.Gauge } type NamedModule struct { @@ -346,7 +347,9 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger log.Logger, clien ) start := time.Now() moduleLabel := prometheus.Labels{"module": module.name} + c.metrics.SNMPInflight.Inc() results, err := ScrapeTarget(client, c.target, c.auth, module.Module, logger, c.metrics) + c.metrics.SNMPInflight.Dec() if err != nil { level.Info(logger).Log("msg", "Error scraping target", "err", err) ch <- prometheus.NewInvalidMetric(prometheus.NewDesc("snmp_error", "Error scraping target", nil, moduleLabel), err) diff --git a/main.go b/main.go index 43193d18..72bdb2b9 100644 --- a/main.go +++ b/main.go @@ -267,6 +267,13 @@ func main() { Help: "Number of SNMP packet retries.", }, ), + SNMPInflight: promauto.NewGauge( + prometheus.GaugeOpts{ + Namespace: namespace, + Name: "request_in_flight", + Help: "Current number of SNMP scrapes being requested.", + }, + ), } http.Handle(*metricsPath, promhttp.Handler()) // Normal metrics endpoint for SNMP exporter itself.