diff --git a/collector/node_config.go b/collector/node_config.go index b7b709f..4f10ead 100644 --- a/collector/node_config.go +++ b/collector/node_config.go @@ -75,8 +75,6 @@ func (c *nodeConfigCollector) Update(client *Client, ch chan<- prometheus.Metric wg.Add(1) go func(node string) { defer wg.Done() - sem <- struct{}{} - defer func() { <-sem }() if err := c.collectNode(client, ch, node, sem); err != nil { emu.Lock() diff --git a/main.go b/main.go index b755a11..00fa6e0 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "strings" + "time" "github.com/alecthomas/kingpin/v2" "github.com/prometheus/client_golang/prometheus" @@ -67,13 +68,17 @@ func main() { registry.MustRegister(versioncollector.NewCollector("pve_exporter")) registry.MustRegister(pveCollector) - http.Handle(*metricsPath, promhttp.HandlerFor( - registry, - promhttp.HandlerOpts{ - ErrorLog: slog.NewLogLogger(logger.Handler(), slog.LevelError), - ErrorHandling: promhttp.ContinueOnError, - MaxRequestsInFlight: 5, - }, + http.Handle(*metricsPath, http.TimeoutHandler( + promhttp.HandlerFor( + registry, + promhttp.HandlerOpts{ + ErrorLog: slog.NewLogLogger(logger.Handler(), slog.LevelError), + ErrorHandling: promhttp.ContinueOnError, + MaxRequestsInFlight: 5, + }, + ), + 120*time.Second, + "Scrape timed out", )) if *metricsPath != "/" {