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
- [#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!
- [#414](https://github.com/influxdb/telegraf/issues/414): Jolokia plugin auth parameters
### Bugfixes
- [#405](https://github.com/influxdb/telegraf/issues/405): Prometheus output cardinality issue

View File

@ -13,9 +13,11 @@ import (
)
type Server struct {
Name string
Host string
Port string
Name string
Host string
Username string
Password string
Port string
}
type Metric struct {
@ -59,6 +61,8 @@ func (j *Jolokia) SampleConfig() string {
name = "stable"
host = "192.168.103.2"
port = "8180"
# username = "myuser"
# password = "mypassword"
# List of metrics collected on above servers
# 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
// 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 {
return err
}
if server.Username != "" || server.Password != "" {
requestUrl.User = url.UserPassword(server.Username, server.Password)
}
out, _ := j.getAttr(requestUrl)