Skip to content
Snippets Groups Projects
Commit 37bc9cf7 authored by Dominik Labuda's avatar Dominik Labuda Committed by Cameron Sparr
Browse files

[plugins] jolokia input plugin: configurable http timeouts (#2098)

parent b762546f
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ plugins, not just statsd. ...@@ -43,6 +43,7 @@ plugins, not just statsd.
- [#1921](https://github.com/influxdata/telegraf/issues/1921): Elasticsearch cluster stats support. - [#1921](https://github.com/influxdata/telegraf/issues/1921): Elasticsearch cluster stats support.
- [#1942](https://github.com/influxdata/telegraf/pull/1942): Change Amazon Kinesis output plugin to use the built-in serializer plugins. - [#1942](https://github.com/influxdata/telegraf/pull/1942): Change Amazon Kinesis output plugin to use the built-in serializer plugins.
- [#1980](https://github.com/influxdata/telegraf/issues/1980): Hide username/password from elasticsearch error log messages. - [#1980](https://github.com/influxdata/telegraf/issues/1980): Hide username/password from elasticsearch error log messages.
- [#2097](https://github.com/influxdata/telegraf/issues/2097): Configurable HTTP timeouts in Jolokia plugin
### Bugfixes ### Bugfixes
......
...@@ -18,7 +18,16 @@ ...@@ -18,7 +18,16 @@
# [inputs.jolokia.proxy] # [inputs.jolokia.proxy]
# host = "127.0.0.1" # host = "127.0.0.1"
# port = "8080" # port = "8080"
## Optional http timeouts
##
## response_header_timeout, if non-zero, specifies the amount of time to wait
## for a server's response headers after fully writing the request.
# response_header_timeout = "3s"
##
## client_timeout specifies a time limit for requests made by this client.
## Includes connection time, any redirects, and reading the response body.
# client_timeout = "4s"
## List of servers exposing jolokia read service ## List of servers exposing jolokia read service
[[inputs.jolokia.servers]] [[inputs.jolokia.servers]]
......
...@@ -11,9 +11,14 @@ import ( ...@@ -11,9 +11,14 @@ import (
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs"
) )
// Default http timeouts
var DefaultResponseHeaderTimeout = internal.Duration{Duration: 3 * time.Second}
var DefaultClientTimeout = internal.Duration{Duration: 4 * time.Second}
type Server struct { type Server struct {
Name string Name string
Host string Host string
...@@ -48,6 +53,9 @@ type Jolokia struct { ...@@ -48,6 +53,9 @@ type Jolokia struct {
Servers []Server Servers []Server
Metrics []Metric Metrics []Metric
Proxy Server Proxy Server
ResponseHeaderTimeout internal.Duration `toml:"response_header_timeout"`
ClientTimeout internal.Duration `toml:"client_timeout"`
} }
const sampleConfig = ` const sampleConfig = `
...@@ -66,6 +74,15 @@ const sampleConfig = ` ...@@ -66,6 +74,15 @@ const sampleConfig = `
# host = "127.0.0.1" # host = "127.0.0.1"
# port = "8080" # port = "8080"
## Optional http timeouts
##
## response_header_timeout, if non-zero, specifies the amount of time to wait
## for a server's response headers after fully writing the request.
# response_header_timeout = "3s"
##
## client_timeout specifies a time limit for requests made by this client.
## Includes connection time, any redirects, and reading the response body.
# client_timeout = "4s"
## List of servers exposing jolokia read service ## List of servers exposing jolokia read service
[[inputs.jolokia.servers]] [[inputs.jolokia.servers]]
...@@ -232,6 +249,15 @@ func extractValues(measurement string, value interface{}, fields map[string]inte ...@@ -232,6 +249,15 @@ func extractValues(measurement string, value interface{}, fields map[string]inte
} }
func (j *Jolokia) Gather(acc telegraf.Accumulator) error { func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
if j.jClient == nil {
tr := &http.Transport{ResponseHeaderTimeout: j.ResponseHeaderTimeout.Duration}
j.jClient = &JolokiaClientImpl{&http.Client{
Transport: tr,
Timeout: j.ClientTimeout.Duration,
}}
}
servers := j.Servers servers := j.Servers
metrics := j.Metrics metrics := j.Metrics
tags := make(map[string]string) tags := make(map[string]string)
...@@ -272,11 +298,9 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error { ...@@ -272,11 +298,9 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
func init() { func init() {
inputs.Add("jolokia", func() telegraf.Input { inputs.Add("jolokia", func() telegraf.Input {
tr := &http.Transport{ResponseHeaderTimeout: time.Duration(3 * time.Second)} return &Jolokia{
client := &http.Client{ ResponseHeaderTimeout: DefaultResponseHeaderTimeout,
Transport: tr, ClientTimeout: DefaultClientTimeout,
Timeout: time.Duration(4 * time.Second),
} }
return &Jolokia{jClient: &JolokiaClientImpl{client: client}}
}) })
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment