Add optional auth credentials to Jolokia plugin

closes #414
This commit is contained in:
Cameron Sparr 2015-12-03 11:46:06 -07:00
parent 6fb7d2883d
commit 7a2eeb7439
2 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@
### Features ### Features
- [#412](https://github.com/influxdb/telegraf/pull/412): Additional memcached stats. Thanks @mgresser! - [#412](https://github.com/influxdb/telegraf/pull/412): Additional memcached stats. Thanks @mgresser!
- [#410](https://github.com/influxdb/telegraf/pull/410): Additional redis metrics. Thanks @vlaadbrain! - [#410](https://github.com/influxdb/telegraf/pull/410): Additional redis metrics. Thanks @vlaadbrain!
- [#414](https://github.com/influxdb/telegraf/issues/414): Jolokia plugin auth parameters
### Bugfixes ### Bugfixes
- [#405](https://github.com/influxdb/telegraf/issues/405): Prometheus output cardinality issue - [#405](https://github.com/influxdb/telegraf/issues/405): Prometheus output cardinality issue

View File

@ -15,6 +15,8 @@ import (
type Server struct { type Server struct {
Name string Name string
Host string Host string
Username string
Password string
Port string Port string
} }
@ -59,6 +61,8 @@ func (j *Jolokia) SampleConfig() string {
name = "stable" name = "stable"
host = "192.168.103.2" host = "192.168.103.2"
port = "8180" port = "8180"
# username = "myuser"
# password = "mypassword"
# List of metrics collected on above servers # List of metrics collected on above servers
# Each metric consists in a name, a jmx path and either a pass or drop slice attributes # Each metric consists in a name, a jmx path and either a pass or drop slice attributes
@ -193,10 +197,14 @@ func (j *Jolokia) Gather(acc plugins.Accumulator) error {
tags["host"] = server.Host tags["host"] = server.Host
// Prepare URL // Prepare URL
requestUrl, err := url.Parse("http://" + server.Host + ":" + server.Port + context + jmxPath) requestUrl, err := url.Parse("http://" + server.Host + ":" +
server.Port + context + jmxPath)
if err != nil { if err != nil {
return err return err
} }
if server.Username != "" || server.Password != "" {
requestUrl.User = url.UserPassword(server.Username, server.Password)
}
out, _ := j.getAttr(requestUrl) out, _ := j.getAttr(requestUrl)