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