Skip to content

Commit

Permalink
configure prometheus handler to limit maximum requests in flight and …
Browse files Browse the repository at this point in the history
…maximum request execution time
  • Loading branch information
damoon committed Jan 25, 2024
1 parent 8303654 commit 57e431b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ to quickly create a Cobra application.`,
IdleTimeout: time.Second * 60,
}

http.Handle(metricsEndpoint, promhttp.Handler())
opts := promhttp.HandlerOpts{
Timeout: 5 * time.Second,
MaxRequestsInFlight: 2,
}
handler := promhttp.InstrumentMetricHandler(
prometheus.DefaultRegisterer,
promhttp.HandlerFor(prometheus.DefaultGatherer, opts),
)
http.Handle(metricsEndpoint, handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(`<html>
<head><title>php-fpm_exporter</title></head>
Expand Down

0 comments on commit 57e431b

Please sign in to comment.