Skip to content

Commit

Permalink
Add SNMPInflight metric (#1119)
Browse files Browse the repository at this point in the history
* Add SNMPInflight metric


---------

Signed-off-by: Kakuya Ando <[email protected]>
  • Loading branch information
servak authored Feb 21, 2024
1 parent 862b410 commit 63d7117
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ type Metrics struct {
SNMPDuration prometheus.Histogram
SNMPPackets prometheus.Counter
SNMPRetries prometheus.Counter
SNMPInflight prometheus.Gauge
}

type NamedModule struct {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 63d7117

Please sign in to comment.