Skip to content

Commit

Permalink
[plugins] jolokia input plugin: configurable http timeouts (#2098)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick1993 authored and sparrc committed Dec 21, 2016
1 parent b77dc90 commit e160728
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ plugins, not just statsd.
- [#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.
- [#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

Expand Down
11 changes: 10 additions & 1 deletion plugins/inputs/jolokia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
# [inputs.jolokia.proxy]
# host = "127.0.0.1"
# 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
[[inputs.jolokia.servers]]
Expand Down
34 changes: 29 additions & 5 deletions plugins/inputs/jolokia/jolokia.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import (
"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"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 {
Name string
Host string
Expand Down Expand Up @@ -48,6 +53,9 @@ type Jolokia struct {
Servers []Server
Metrics []Metric
Proxy Server

ResponseHeaderTimeout internal.Duration `toml:"response_header_timeout"`
ClientTimeout internal.Duration `toml:"client_timeout"`
}

const sampleConfig = `
Expand All @@ -66,6 +74,15 @@ const sampleConfig = `
# host = "127.0.0.1"
# 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
[[inputs.jolokia.servers]]
Expand Down Expand Up @@ -232,6 +249,15 @@ func extractValues(measurement string, value interface{}, fields map[string]inte
}

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
metrics := j.Metrics
tags := make(map[string]string)
Expand Down Expand Up @@ -272,11 +298,9 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {

func init() {
inputs.Add("jolokia", func() telegraf.Input {
tr := &http.Transport{ResponseHeaderTimeout: time.Duration(3 * time.Second)}
client := &http.Client{
Transport: tr,
Timeout: time.Duration(4 * time.Second),
return &Jolokia{
ResponseHeaderTimeout: DefaultResponseHeaderTimeout,
ClientTimeout: DefaultClientTimeout,
}
return &Jolokia{jClient: &JolokiaClientImpl{client: client}}
})
}

0 comments on commit e160728

Please sign in to comment.