From 5849de91245f7fb7fb7a365d2ffa7431071a1dfb Mon Sep 17 00:00:00 2001 From: Kakuya Ando Date: Tue, 20 Feb 2024 09:31:37 +0900 Subject: [PATCH 1/3] 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..0575de2f 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 { @@ -403,6 +404,8 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger log.Logger, clien // Collect implements Prometheus.Collector. func (c Collector) Collect(ch chan<- prometheus.Metric) { + c.metrics.SNMPInflight.Inc() + defer c.metrics.SNMPInflight.Dec() wg := sync.WaitGroup{} workerCount := c.concurrency if workerCount < 1 { diff --git a/main.go b/main.go index 43193d18..31dcdbb3 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 requests being served.", + }, + ), } http.Handle(*metricsPath, promhttp.Handler()) // Normal metrics endpoint for SNMP exporter itself. From 29ac87183e70a22465a146f8dcf7476a4d3ef67d Mon Sep 17 00:00:00 2001 From: Kakuya Ando Date: Tue, 20 Feb 2024 21:24:47 +0900 Subject: [PATCH 2/3] Increment SNMPInflight metric during scraping Signed-off-by: Kakuya Ando --- collector/collector.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/collector/collector.go b/collector/collector.go index 0575de2f..1b7337ac 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -347,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) @@ -404,8 +406,6 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger log.Logger, clien // Collect implements Prometheus.Collector. func (c Collector) Collect(ch chan<- prometheus.Metric) { - c.metrics.SNMPInflight.Inc() - defer c.metrics.SNMPInflight.Dec() wg := sync.WaitGroup{} workerCount := c.concurrency if workerCount < 1 { From 83ac38bd4339fd943730b3dfdacf64e08a2dc40f Mon Sep 17 00:00:00 2001 From: Kakuya Ando Date: Wed, 21 Feb 2024 09:18:12 +0900 Subject: [PATCH 3/3] Update metric help text for SNMP scrapes Signed-off-by: Kakuya Ando --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 31dcdbb3..72bdb2b9 100644 --- a/main.go +++ b/main.go @@ -271,7 +271,7 @@ func main() { prometheus.GaugeOpts{ Namespace: namespace, Name: "request_in_flight", - Help: "Current number of requests being served.", + Help: "Current number of SNMP scrapes being requested.", }, ), }