Skip to content

Commit 0e1c515

Browse files
committed
configure prometheus handler to limit maximum requests in flight and maximum request execution time
1 parent c28f059 commit 0e1c515

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ to quickly create a Cobra application.`,
7171
IdleTimeout: time.Second * 60,
7272
}
7373

74-
http.Handle(metricsEndpoint, promhttp.Handler())
74+
opts := promhttp.HandlerOpts{
75+
Timeout: 5 * time.Second,
76+
MaxRequestsInFlight: 2,
77+
}
78+
handler := promhttp.InstrumentMetricHandler(
79+
prometheus.DefaultRegisterer,
80+
promhttp.HandlerFor(prometheus.DefaultGatherer, opts),
81+
)
82+
http.Handle(metricsEndpoint, handler)
7583
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
7684
_, err := w.Write([]byte(`<html>
7785
<head><title>php-fpm_exporter</title></head>

0 commit comments

Comments
 (0)