allow changing jolokia delimiter (#2255)

This commit is contained in:
Patrick Hemmer 2017-01-12 06:08:22 -05:00 committed by Cameron Sparr
parent 947e1909ff
commit b7d29ca0e9
3 changed files with 23 additions and 12 deletions

View File

@ -44,6 +44,7 @@ plugins, not just statsd.
- [#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 - [#2097](https://github.com/influxdata/telegraf/issues/2097): Configurable HTTP timeouts in Jolokia plugin
- [#2255](https://github.com/influxdata/telegraf/pull/2255): Allow changing jolokia attribute delimiter
### Bugfixes ### Bugfixes

View File

@ -53,6 +53,7 @@ type Jolokia struct {
Servers []Server Servers []Server
Metrics []Metric Metrics []Metric
Proxy Server Proxy Server
Delimiter string
ResponseHeaderTimeout internal.Duration `toml:"response_header_timeout"` ResponseHeaderTimeout internal.Duration `toml:"response_header_timeout"`
ClientTimeout internal.Duration `toml:"client_timeout"` ClientTimeout internal.Duration `toml:"client_timeout"`
@ -84,6 +85,13 @@ const sampleConfig = `
## Includes connection time, any redirects, and reading the response body. ## Includes connection time, any redirects, and reading the response body.
# client_timeout = "4s" # client_timeout = "4s"
## Attribute delimiter
##
## When multiple attributes are returned for a single
## [inputs.jolokia.metrics], the field name is a concatenation of the metric
## name, and the attribute name, separated by the given delimiter.
# delimiter = "_"
## List of servers exposing jolokia read service ## List of servers exposing jolokia read service
[[inputs.jolokia.servers]] [[inputs.jolokia.servers]]
name = "as-server-01" name = "as-server-01"
@ -238,10 +246,10 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
return req, nil return req, nil
} }
func extractValues(measurement string, value interface{}, fields map[string]interface{}) { func (j *Jolokia) extractValues(measurement string, value interface{}, fields map[string]interface{}) {
if mapValues, ok := value.(map[string]interface{}); ok { if mapValues, ok := value.(map[string]interface{}); ok {
for k2, v2 := range mapValues { for k2, v2 := range mapValues {
extractValues(measurement+"_"+k2, v2, fields) j.extractValues(measurement+j.Delimiter+k2, v2, fields)
} }
} else { } else {
fields[measurement] = value fields[measurement] = value
@ -282,7 +290,7 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
fmt.Printf("Error handling response: %s\n", err) fmt.Printf("Error handling response: %s\n", err)
} else { } else {
if values, ok := out["value"]; ok { if values, ok := out["value"]; ok {
extractValues(measurement, values, fields) j.extractValues(measurement, values, fields)
} else { } else {
fmt.Printf("Missing key 'value' in output response\n") fmt.Printf("Missing key 'value' in output response\n")
} }
@ -301,6 +309,7 @@ func init() {
return &Jolokia{ return &Jolokia{
ResponseHeaderTimeout: DefaultResponseHeaderTimeout, ResponseHeaderTimeout: DefaultResponseHeaderTimeout,
ClientTimeout: DefaultClientTimeout, ClientTimeout: DefaultClientTimeout,
Delimiter: "_",
} }
}) })
} }

View File

@ -107,6 +107,7 @@ func genJolokiaClientStub(response string, statusCode int, servers []Server, met
jClient: jolokiaClientStub{responseBody: response, statusCode: statusCode}, jClient: jolokiaClientStub{responseBody: response, statusCode: statusCode},
Servers: servers, Servers: servers,
Metrics: metrics, Metrics: metrics,
Delimiter: "_",
} }
} }