Jolokia plugin expects a URL now, instead of several parameters like "host" and "port".
This commit is contained in:
parent
26315bfbea
commit
d3d58e480e
|
@ -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()
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
name = "as-server-01"
|
||||
host = "127.0.0.1"
|
||||
port = "8080"
|
||||
https = false
|
||||
# username = "myuser"
|
||||
# password = "mypassword"
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue