diff --git a/cmd/prometheus/config.go b/cmd/prometheus/config.go index 234e15f1a..5410a6f62 100644 --- a/cmd/prometheus/config.go +++ b/cmd/prometheus/config.go @@ -84,6 +84,10 @@ func init() { &cfg.web.ReadTimeout, "web.read-timeout", 30*time.Second, "Maximum duration before timing out read of the request, and closing idle connections.", ) + cfg.fs.IntVar( + &cfg.web.MaxConnections, "web.max-connections", 100, + "Maximum number of simultaneous connections.", + ) cfg.fs.StringVar( &cfg.prometheusURL, "web.external-url", "", "The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically.", diff --git a/web/web.go b/web/web.go index ea571abac..e0320fb6a 100644 --- a/web/web.go +++ b/web/web.go @@ -37,6 +37,7 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/common/route" "golang.org/x/net/context" + "golang.org/x/net/netutil" "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/notifier" @@ -112,6 +113,7 @@ type Options struct { ListenAddress string ReadTimeout time.Duration + MaxConnections int ExternalURL *url.URL RoutePrefix string MetricsPath string @@ -253,7 +255,13 @@ func (h *Handler) Run() { ErrorLog: log.NewErrorLogger(), ReadTimeout: h.options.ReadTimeout, } - h.listenErrCh <- server.ListenAndServe() + listener, err := net.Listen("tcp", h.options.ListenAddress) + if err != nil { + h.listenErrCh <- err + } else { + limitedListener := netutil.LimitListener(listener, h.options.MaxConnections) + h.listenErrCh <- server.Serve(limitedListener) + } } func (h *Handler) alerts(w http.ResponseWriter, r *http.Request) {