From d3d58e480e83c3d5712e35720b8ba1aff9c7ebe3 Mon Sep 17 00:00:00 2001 From: Matthias Moser Date: Tue, 9 Aug 2016 19:27:59 +0200 Subject: [PATCH] Jolokia plugin expects a URL now, instead of several parameters like "host" and "port". --- CHANGELOG.md | 1 + plugins/inputs/jolokia/README.md | 1 + plugins/inputs/jolokia/jolokia.go | 23 +++++++++++------------ plugins/inputs/jolokia/jolokia_test.go | 5 ++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8cef8831..55df731e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ consistent with the behavior of `collection_jitter`. ### Features +- [#1632](https://github.com/influxdata/telegraf/pull/1632): Add HTTPS support in jolokia plugin. - [#1413](https://github.com/influxdata/telegraf/issues/1413): Separate container_version from container_image tag. - [#1525](https://github.com/influxdata/telegraf/pull/1525): Support setting per-device and total metrics for Docker network and blockio. - [#1466](https://github.com/influxdata/telegraf/pull/1466): MongoDB input plugin: adding per DB stats from db.stats() diff --git a/plugins/inputs/jolokia/README.md b/plugins/inputs/jolokia/README.md index 596dbed5f..c2df37734 100644 --- a/plugins/inputs/jolokia/README.md +++ b/plugins/inputs/jolokia/README.md @@ -24,6 +24,7 @@ name = "as-server-01" host = "127.0.0.1" port = "8080" + https = false # username = "myuser" # password = "mypassword" diff --git a/plugins/inputs/jolokia/jolokia.go b/plugins/inputs/jolokia/jolokia.go index 53bb65fd0..b73cd52cb 100644 --- a/plugins/inputs/jolokia/jolokia.go +++ b/plugins/inputs/jolokia/jolokia.go @@ -9,17 +9,16 @@ import ( "net/http" "net/url" "time" - + "strings" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" ) type Server struct { Name string - Host string + Url string Username string Password string - Port string } type Metric struct { @@ -61,15 +60,14 @@ const sampleConfig = ` ## proxy address configurations. ## Remember to change host address to fit your environment. # [inputs.jolokia.proxy] - # host = "127.0.0.1" + # url = "127.0.0.1" # port = "8080" ## List of servers exposing jolokia read service [[inputs.jolokia.servers]] name = "as-server-01" - host = "127.0.0.1" - port = "8080" + url = "https://as-server-01:8080 # username = "myuser" # password = "mypassword" @@ -165,8 +163,10 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e // Add target, only in proxy mode if j.Mode == "proxy" { - serviceUrl := fmt.Sprintf("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", - server.Host, server.Port) + serverUrlForScheme, err := url.Parse(server.Url) + replacedUrl := strings.Replace(server.Url, serverUrlForScheme.Scheme + "://", "", 1) + + serviceUrl := fmt.Sprintf("service:jmx:rmi:///jndi/rmi://%s/jmxrmi", replacedUrl) target := map[string]string{ "url": serviceUrl, @@ -185,7 +185,7 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e proxy := j.Proxy // Prepare ProxyURL - proxyUrl, err := url.Parse("http://" + proxy.Host + ":" + proxy.Port + context) + proxyUrl, err := url.Parse(proxy.Url + context) if err != nil { return nil, err } @@ -196,7 +196,7 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e jolokiaUrl = proxyUrl } else { - serverUrl, err := url.Parse("http://" + server.Host + ":" + server.Port + context) + serverUrl, err := url.Parse(server.Url + context) if err != nil { return nil, err } @@ -227,8 +227,7 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error { for _, server := range servers { tags["jolokia_name"] = server.Name - tags["jolokia_port"] = server.Port - tags["jolokia_host"] = server.Host + tags["jolokia_url"] = server.Url fields := make(map[string]interface{}) for _, metric := range metrics { diff --git a/plugins/inputs/jolokia/jolokia_test.go b/plugins/inputs/jolokia/jolokia_test.go index 13724b937..16349092e 100644 --- a/plugins/inputs/jolokia/jolokia_test.go +++ b/plugins/inputs/jolokia/jolokia_test.go @@ -46,7 +46,7 @@ const invalidJSON = "I don't think this is JSON" const empty = "" -var Servers = []Server{Server{Name: "as1", Host: "127.0.0.1", Port: "8080"}} +var Servers = []Server{Server{Name: "as1", Url: "127.0.0.1:8080"}} var HeapMetric = Metric{Name: "heap_memory_usage", Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"} var UsedHeapMetric = Metric{Name: "heap_memory_usage", @@ -96,8 +96,7 @@ func TestHttpJsonMultiValue(t *testing.T) { "heap_memory_usage_used": 203288528.0, } tags := map[string]string{ - "jolokia_host": "127.0.0.1", - "jolokia_port": "8080", + "jolokia_url": "127.0.0.1:8080", "jolokia_name": "as1", } acc.AssertContainsTaggedFields(t, "jolokia", fields, tags)