diff --git a/app/vmalert/README.md b/app/vmalert/README.md index 3b1df81030..77d01a160b 100644 --- a/app/vmalert/README.md +++ b/app/vmalert/README.md @@ -166,8 +166,10 @@ The shortlist of configuration flags is the following: Optional basic auth password for -datasource.url -datasource.basicAuth.username string Optional basic auth username for -datasource.url - -datasource.lookback duration + -datasource.lookback duration Lookback defines how far to look into past when evaluating queries. For example, if datasource.lookback=5m then param "time" with value now()-5m will be added to every query. + -datasource.maxIdleConnections int + Defines the number of idle (keep-alive connections) to configured datasource.Consider to set this value equal to the value: groups_total * group.concurrency. Too low value may result into high number of sockets in TIME_WAIT state. (default 100) -datasource.tlsCAFile string Optional path to TLS CA file to use for verifying connections to -datasource.url. By default system CA is used -datasource.tlsCertFile string diff --git a/app/vmalert/datasource/init.go b/app/vmalert/datasource/init.go index 89814dde59..62e7848eb0 100644 --- a/app/vmalert/datasource/init.go +++ b/app/vmalert/datasource/init.go @@ -24,6 +24,8 @@ var ( lookBack = flag.Duration("datasource.lookback", 0, "Lookback defines how far to look into past when evaluating queries. "+ "For example, if datasource.lookback=5m then param \"time\" with value now()-5m will be added to every query.") + maxIdleConnections = flag.Int("datasource.maxIdleConnections", 100, "Defines the number of idle (keep-alive connections) to configured datasource."+ + "Consider to set this value equal to the value: groups_total * group.concurrency. Too low value may result into high number of sockets in TIME_WAIT state.") ) // Init creates a Querier from provided flag values. @@ -36,6 +38,7 @@ func Init() (Querier, error) { if err != nil { return nil, fmt.Errorf("failed to create transport: %w", err) } + tr.MaxIdleConns = *maxIdleConnections c := &http.Client{Transport: tr} return NewVMStorage(*addr, *basicAuthUsername, *basicAuthPassword, *lookBack, c), nil }