Jolokia plugin expects a URL now, instead of several parameters like "host" and "port".

This commit is contained in:
Matthias Moser 2016-08-09 19:27:59 +02:00
parent 26315bfbea
commit d3d58e480e
4 changed files with 15 additions and 15 deletions

View File

@ -42,6 +42,7 @@ consistent with the behavior of `collection_jitter`.
### Features ### 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. - [#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. - [#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() - [#1466](https://github.com/influxdata/telegraf/pull/1466): MongoDB input plugin: adding per DB stats from db.stats()

View File

@ -24,6 +24,7 @@
name = "as-server-01" name = "as-server-01"
host = "127.0.0.1" host = "127.0.0.1"
port = "8080" port = "8080"
https = false
# username = "myuser" # username = "myuser"
# password = "mypassword" # password = "mypassword"

View File

@ -9,17 +9,16 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"strings"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs"
) )
type Server struct { type Server struct {
Name string Name string
Host string Url string
Username string Username string
Password string Password string
Port string
} }
type Metric struct { type Metric struct {
@ -61,15 +60,14 @@ const sampleConfig = `
## proxy address configurations. ## proxy address configurations.
## Remember to change host address to fit your environment. ## Remember to change host address to fit your environment.
# [inputs.jolokia.proxy] # [inputs.jolokia.proxy]
# host = "127.0.0.1" # url = "127.0.0.1"
# port = "8080" # port = "8080"
## 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"
host = "127.0.0.1" url = "https://as-server-01:8080
port = "8080"
# username = "myuser" # username = "myuser"
# password = "mypassword" # password = "mypassword"
@ -165,8 +163,10 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
// Add target, only in proxy mode // Add target, only in proxy mode
if j.Mode == "proxy" { if j.Mode == "proxy" {
serviceUrl := fmt.Sprintf("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", serverUrlForScheme, err := url.Parse(server.Url)
server.Host, server.Port) replacedUrl := strings.Replace(server.Url, serverUrlForScheme.Scheme + "://", "", 1)
serviceUrl := fmt.Sprintf("service:jmx:rmi:///jndi/rmi://%s/jmxrmi", replacedUrl)
target := map[string]string{ target := map[string]string{
"url": serviceUrl, "url": serviceUrl,
@ -185,7 +185,7 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
proxy := j.Proxy proxy := j.Proxy
// Prepare ProxyURL // Prepare ProxyURL
proxyUrl, err := url.Parse("http://" + proxy.Host + ":" + proxy.Port + context) proxyUrl, err := url.Parse(proxy.Url + context)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -196,7 +196,7 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
jolokiaUrl = proxyUrl jolokiaUrl = proxyUrl
} else { } else {
serverUrl, err := url.Parse("http://" + server.Host + ":" + server.Port + context) serverUrl, err := url.Parse(server.Url + context)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -227,8 +227,7 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
for _, server := range servers { for _, server := range servers {
tags["jolokia_name"] = server.Name tags["jolokia_name"] = server.Name
tags["jolokia_port"] = server.Port tags["jolokia_url"] = server.Url
tags["jolokia_host"] = server.Host
fields := make(map[string]interface{}) fields := make(map[string]interface{})
for _, metric := range metrics { for _, metric := range metrics {

View File

@ -46,7 +46,7 @@ const invalidJSON = "I don't think this is JSON"
const empty = "" 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", var HeapMetric = Metric{Name: "heap_memory_usage",
Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"} Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"}
var UsedHeapMetric = Metric{Name: "heap_memory_usage", var UsedHeapMetric = Metric{Name: "heap_memory_usage",
@ -96,8 +96,7 @@ func TestHttpJsonMultiValue(t *testing.T) {
"heap_memory_usage_used": 203288528.0, "heap_memory_usage_used": 203288528.0,
} }
tags := map[string]string{ tags := map[string]string{
"jolokia_host": "127.0.0.1", "jolokia_url": "127.0.0.1:8080",
"jolokia_port": "8080",
"jolokia_name": "as1", "jolokia_name": "as1",
} }
acc.AssertContainsTaggedFields(t, "jolokia", fields, tags) acc.AssertContainsTaggedFields(t, "jolokia", fields, tags)