feat: add timeout-setting to Graylog-plugin (#10220)

This commit is contained in:
Sebastian Thörn 2021-12-21 17:10:04 +01:00 committed by GitHub
parent 9f7e8befae
commit a0242035aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -30,6 +30,9 @@ Note: if namespace end point specified metrics array will be ignored for that ca
"http://[graylog-server-ip]:12900/system/metrics/multiple",
]
## Set timeout (default 5 seconds)
# timeout = "5s"
## Metrics list
## List of metrics can be found on Graylog webservice documentation.
## Or by hitting the web service api at:

View File

@ -14,6 +14,7 @@ import (
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/tls"
"github.com/influxdata/telegraf/plugins/inputs"
)
@ -34,6 +35,7 @@ type GrayLog struct {
Metrics []string
Username string
Password string
Timeout config.Duration
tls.ClientConfig
client HTTPClient
@ -89,6 +91,9 @@ var sampleConfig = `
"http://[graylog-server-ip]:12900/system/metrics/multiple",
]
## Set timeout (default 5 seconds)
# timeout = "5s"
## Metrics list
## List of metrics can be found on Graylog webservice documentation.
## Or by hitting the the web service api at:
@ -128,12 +133,12 @@ func (h *GrayLog) Gather(acc telegraf.Accumulator) error {
return err
}
tr := &http.Transport{
ResponseHeaderTimeout: 3 * time.Second,
ResponseHeaderTimeout: time.Duration(h.Timeout),
TLSClientConfig: tlsCfg,
}
client := &http.Client{
Transport: tr,
Timeout: 4 * time.Second,
Timeout: time.Duration(h.Timeout),
}
h.client.SetHTTPClient(client)
}
@ -285,7 +290,8 @@ func (h *GrayLog) sendRequest(serverURL string) (string, float64, error) {
func init() {
inputs.Add("graylog", func() telegraf.Input {
return &GrayLog{
client: &RealHTTPClient{},
client: &RealHTTPClient{},
Timeout: config.Duration(5 * time.Second),
}
})
}