chore(inputs.jolokia2): Move agent and proxy one level up (#11637)
This commit is contained in:
parent
8d416c4b7a
commit
78bdf9a1b2
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package jolokia2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package jolokia2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package jolokia2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package jolokia2
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package jolokia2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build !custom || inputs || inputs.jolokia2
|
|
||||||
|
|
||||||
package all
|
|
||||||
|
|
||||||
import _ "github.com/influxdata/telegraf/plugins/inputs/jolokia2" // register plugin
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !custom || inputs || inputs.jolokia2_agent
|
||||||
|
|
||||||
|
package all
|
||||||
|
|
||||||
|
import _ "github.com/influxdata/telegraf/plugins/inputs/jolokia2_agent" // register plugin
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
//go:build !custom || inputs || inputs.jolokia2_proxy
|
||||||
|
|
||||||
|
package all
|
||||||
|
|
||||||
|
import _ "github.com/influxdata/telegraf/plugins/inputs/jolokia2_proxy" // register plugin
|
||||||
|
|
@ -1,102 +0,0 @@
|
||||||
package jolokia2_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestJolokia2_ClientAuthRequest(t *testing.T) {
|
|
||||||
var username string
|
|
||||||
var password string
|
|
||||||
var requests []map[string]interface{}
|
|
||||||
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
username, password, _ = r.BasicAuth()
|
|
||||||
|
|
||||||
body, _ := io.ReadAll(r.Body)
|
|
||||||
require.NoError(t, json.Unmarshal(body, &requests))
|
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
plugin := SetupPlugin(t, fmt.Sprintf(`
|
|
||||||
[jolokia2_agent]
|
|
||||||
urls = ["%s/jolokia"]
|
|
||||||
username = "sally"
|
|
||||||
password = "seashore"
|
|
||||||
[[jolokia2_agent.metric]]
|
|
||||||
name = "hello"
|
|
||||||
mbean = "hello:foo=bar"
|
|
||||||
`, server.URL))
|
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
|
||||||
require.NoError(t, plugin.Gather(&acc))
|
|
||||||
|
|
||||||
require.EqualValuesf(t, "sally", username, "Expected to post with username %s, but was %s", "sally", username)
|
|
||||||
require.EqualValuesf(t, "seashore", password, "Expected to post with password %s, but was %s", "seashore", password)
|
|
||||||
require.NotZero(t, len(requests), "Expected to post a request body, but was empty.")
|
|
||||||
|
|
||||||
request := requests[0]["mbean"]
|
|
||||||
require.EqualValuesf(t, "hello:foo=bar", request, "Expected to query mbean %s, but was %s", "hello:foo=bar", request)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJolokia2_ClientProxyAuthRequest(t *testing.T) {
|
|
||||||
var requests []map[string]interface{}
|
|
||||||
|
|
||||||
var username string
|
|
||||||
var password string
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
username, password, _ = r.BasicAuth()
|
|
||||||
|
|
||||||
body, _ := io.ReadAll(r.Body)
|
|
||||||
require.NoError(t, json.Unmarshal(body, &requests))
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
_, err := fmt.Fprintf(w, "[]")
|
|
||||||
require.NoError(t, err)
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
|
|
||||||
plugin := SetupPlugin(t, fmt.Sprintf(`
|
|
||||||
[jolokia2_proxy]
|
|
||||||
url = "%s/jolokia"
|
|
||||||
username = "sally"
|
|
||||||
password = "seashore"
|
|
||||||
|
|
||||||
[[jolokia2_proxy.target]]
|
|
||||||
url = "service:jmx:rmi:///jndi/rmi://target:9010/jmxrmi"
|
|
||||||
username = "jack"
|
|
||||||
password = "benimble"
|
|
||||||
|
|
||||||
[[jolokia2_proxy.metric]]
|
|
||||||
name = "hello"
|
|
||||||
mbean = "hello:foo=bar"
|
|
||||||
`, server.URL))
|
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
|
||||||
require.NoError(t, plugin.Gather(&acc))
|
|
||||||
require.EqualValuesf(t, "sally", username, "Expected to post with username %s, but was %s", "sally", username)
|
|
||||||
require.EqualValuesf(t, "seashore", password, "Expected to post with password %s, but was %s", "seashore", password)
|
|
||||||
require.NotZero(t, len(requests), "Expected to post a request body, but was empty.")
|
|
||||||
|
|
||||||
request := requests[0]
|
|
||||||
expected := "hello:foo=bar"
|
|
||||||
require.EqualValuesf(t, expected, request["mbean"], "Expected to query mbean %s, but was %s", expected, request["mbean"])
|
|
||||||
|
|
||||||
target, ok := request["target"].(map[string]interface{})
|
|
||||||
require.True(t, ok, "Expected a proxy target, but was empty.")
|
|
||||||
|
|
||||||
expected = "service:jmx:rmi:///jndi/rmi://target:9010/jmxrmi"
|
|
||||||
require.Equalf(t, expected, target["url"], "Expected proxy target url %s, but was %s", expected, target["url"])
|
|
||||||
expected = "jack"
|
|
||||||
require.Equalf(t, expected, target["user"], "Expected proxy target username %s, but was %s", expected, target["user"])
|
|
||||||
expected = "benimble"
|
|
||||||
require.Equalf(t, expected, target["password"], "Expected proxy target username %s, but was %s", expected, target["password"])
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package jolokia2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/influxdata/telegraf"
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/common"
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/jolokia2_agent"
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/jolokia2_proxy"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
inputs.Add("jolokia2_agent", func() telegraf.Input {
|
|
||||||
return &jolokia2_agent.JolokiaAgent{
|
|
||||||
Metrics: []common.MetricConfig{},
|
|
||||||
DefaultFieldSeparator: ".",
|
|
||||||
}
|
|
||||||
})
|
|
||||||
inputs.Add("jolokia2_proxy", func() telegraf.Input {
|
|
||||||
return &jolokia2_proxy.JolokiaProxy{
|
|
||||||
Metrics: []common.MetricConfig{},
|
|
||||||
DefaultFieldSeparator: ".",
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
# Jolokia2 Agent Input Plugin
|
|
||||||
|
|
||||||
The `jolokia2_agent` input plugin reads JMX metrics from one or more
|
|
||||||
[Jolokia agent](https://jolokia.org/agent/jvm.html) REST endpoints.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
```toml @sample.conf
|
|
||||||
# Read JMX metrics from a Jolokia REST agent endpoint
|
|
||||||
[[inputs.jolokia2_agent]]
|
|
||||||
# default_tag_prefix = ""
|
|
||||||
# default_field_prefix = ""
|
|
||||||
# default_field_separator = "."
|
|
||||||
|
|
||||||
# Add agents URLs to query
|
|
||||||
urls = ["http://localhost:8080/jolokia"]
|
|
||||||
# username = ""
|
|
||||||
# password = ""
|
|
||||||
# response_timeout = "5s"
|
|
||||||
|
|
||||||
## Optional origin URL to include as a header in the request. Some endpoints
|
|
||||||
## may reject an empty origin.
|
|
||||||
# origin = ""
|
|
||||||
|
|
||||||
## Optional TLS config
|
|
||||||
# tls_ca = "/var/private/ca.pem"
|
|
||||||
# tls_cert = "/var/private/client.pem"
|
|
||||||
# tls_key = "/var/private/client-key.pem"
|
|
||||||
# insecure_skip_verify = false
|
|
||||||
|
|
||||||
## Add metrics to read
|
|
||||||
[[inputs.jolokia2_agent.metric]]
|
|
||||||
name = "java_runtime"
|
|
||||||
mbean = "java.lang:type=Runtime"
|
|
||||||
paths = ["Uptime"]
|
|
||||||
```
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
# Jolokia2 Proxy Input Plugin
|
|
||||||
|
|
||||||
The `jolokia2_proxy` input plugin reads JMX metrics from one or more _targets_
|
|
||||||
by interacting with a [Jolokia proxy](https://jolokia.org/features/proxy.html)
|
|
||||||
REST endpoint.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
```toml @sample.conf
|
|
||||||
# Read JMX metrics from a Jolokia REST proxy endpoint
|
|
||||||
[[inputs.jolokia2_proxy]]
|
|
||||||
# default_tag_prefix = ""
|
|
||||||
# default_field_prefix = ""
|
|
||||||
# default_field_separator = "."
|
|
||||||
|
|
||||||
## Proxy agent
|
|
||||||
url = "http://localhost:8080/jolokia"
|
|
||||||
# username = ""
|
|
||||||
# password = ""
|
|
||||||
# response_timeout = "5s"
|
|
||||||
|
|
||||||
## Optional origin URL to include as a header in the request. Some endpoints
|
|
||||||
## may reject an empty origin.
|
|
||||||
# origin = ""
|
|
||||||
|
|
||||||
## Optional TLS config
|
|
||||||
# tls_ca = "/var/private/ca.pem"
|
|
||||||
# tls_cert = "/var/private/client.pem"
|
|
||||||
# tls_key = "/var/private/client-key.pem"
|
|
||||||
# insecure_skip_verify = false
|
|
||||||
|
|
||||||
## Add proxy targets to query
|
|
||||||
# default_target_username = ""
|
|
||||||
# default_target_password = ""
|
|
||||||
[[inputs.jolokia2_proxy.target]]
|
|
||||||
url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
|
|
||||||
# username = ""
|
|
||||||
# password = ""
|
|
||||||
|
|
||||||
## Add metrics to read
|
|
||||||
[[inputs.jolokia2_proxy.metric]]
|
|
||||||
name = "java_runtime"
|
|
||||||
mbean = "java.lang:type=Runtime"
|
|
||||||
paths = ["Uptime"]
|
|
||||||
```
|
|
||||||
|
|
@ -1,25 +1,36 @@
|
||||||
# Jolokia2 Input Plugin
|
# Jolokia2 Agent Input Plugin
|
||||||
|
|
||||||
The [Jolokia](http://jolokia.org) _agent_ and _proxy_ input plugins collect JMX
|
|
||||||
metrics from an HTTP endpoint using Jolokia's [JSON-over-HTTP
|
|
||||||
protocol](https://jolokia.org/reference/html/protocol.html).
|
|
||||||
|
|
||||||
* [jolokia2_agent Configuration](jolokia2_agent/README.md)
|
|
||||||
* [jolokia2_proxy Configuration](jolokia2_proxy/README.md)
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
### Jolokia Agent Configuration
|
|
||||||
|
|
||||||
The `jolokia2_agent` input plugin reads JMX metrics from one or more
|
The `jolokia2_agent` input plugin reads JMX metrics from one or more
|
||||||
[Jolokia agent](https://jolokia.org/agent/jvm.html) REST endpoints.
|
[Jolokia agent](https://jolokia.org/agent/jvm.html) REST endpoints.
|
||||||
|
|
||||||
```toml @sample.conf
|
## Configuration
|
||||||
[[inputs.jolokia2_agent]]
|
|
||||||
urls = ["http://agent:8080/jolokia"]
|
|
||||||
|
|
||||||
|
```toml @sample.conf
|
||||||
|
# Read JMX metrics from a Jolokia REST agent endpoint
|
||||||
|
[[inputs.jolokia2_agent]]
|
||||||
|
# default_tag_prefix = ""
|
||||||
|
# default_field_prefix = ""
|
||||||
|
# default_field_separator = "."
|
||||||
|
|
||||||
|
# Add agents URLs to query
|
||||||
|
urls = ["http://localhost:8080/jolokia"]
|
||||||
|
# username = ""
|
||||||
|
# password = ""
|
||||||
|
# response_timeout = "5s"
|
||||||
|
|
||||||
|
## Optional origin URL to include as a header in the request. Some endpoints
|
||||||
|
## may reject an empty origin.
|
||||||
|
# origin = ""
|
||||||
|
|
||||||
|
## Optional TLS config
|
||||||
|
# tls_ca = "/var/private/ca.pem"
|
||||||
|
# tls_cert = "/var/private/client.pem"
|
||||||
|
# tls_key = "/var/private/client-key.pem"
|
||||||
|
# insecure_skip_verify = false
|
||||||
|
|
||||||
|
## Add metrics to read
|
||||||
[[inputs.jolokia2_agent.metric]]
|
[[inputs.jolokia2_agent.metric]]
|
||||||
name = "jvm_runtime"
|
name = "java_runtime"
|
||||||
mbean = "java.lang:type=Runtime"
|
mbean = "java.lang:type=Runtime"
|
||||||
paths = ["Uptime"]
|
paths = ["Uptime"]
|
||||||
```
|
```
|
||||||
|
|
@ -40,54 +51,7 @@ Optionally, specify TLS options for communicating with agents:
|
||||||
paths = ["Uptime"]
|
paths = ["Uptime"]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Jolokia Proxy Configuration
|
### Metric Configuration
|
||||||
|
|
||||||
The `jolokia2_proxy` input plugin reads JMX metrics from one or more _targets_
|
|
||||||
by interacting with a [Jolokia proxy](https://jolokia.org/features/proxy.html)
|
|
||||||
REST endpoint.
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[[inputs.jolokia2_proxy]]
|
|
||||||
url = "http://proxy:8080/jolokia"
|
|
||||||
|
|
||||||
#default_target_username = ""
|
|
||||||
#default_target_password = ""
|
|
||||||
[[inputs.jolokia2_proxy.target]]
|
|
||||||
url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
|
|
||||||
# username = ""
|
|
||||||
# password = ""
|
|
||||||
|
|
||||||
[[inputs.jolokia2_proxy.metric]]
|
|
||||||
name = "jvm_runtime"
|
|
||||||
mbean = "java.lang:type=Runtime"
|
|
||||||
paths = ["Uptime"]
|
|
||||||
```
|
|
||||||
|
|
||||||
Optionally, specify TLS options for communicating with proxies:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[[inputs.jolokia2_proxy]]
|
|
||||||
url = "https://proxy:8080/jolokia"
|
|
||||||
|
|
||||||
tls_ca = "/var/private/ca.pem"
|
|
||||||
tls_cert = "/var/private/client.pem"
|
|
||||||
tls_key = "/var/private/client-key.pem"
|
|
||||||
#insecure_skip_verify = false
|
|
||||||
|
|
||||||
#default_target_username = ""
|
|
||||||
#default_target_password = ""
|
|
||||||
[[inputs.jolokia2_proxy.target]]
|
|
||||||
url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
|
|
||||||
# username = ""
|
|
||||||
# password = ""
|
|
||||||
|
|
||||||
[[inputs.jolokia2_agent.metric]]
|
|
||||||
name = "jvm_runtime"
|
|
||||||
mbean = "java.lang:type=Runtime"
|
|
||||||
paths = ["Uptime"]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Jolokia Metric Configuration
|
|
||||||
|
|
||||||
Each `metric` declaration generates a Jolokia request to fetch telemetry from a
|
Each `metric` declaration generates a Jolokia request to fetch telemetry from a
|
||||||
JMX MBean.
|
JMX MBean.
|
||||||
|
|
@ -180,8 +144,8 @@ gathering fields together into the single metric.
|
||||||
kafka_topic,topic=my-topic BytesOutPerSec.MeanRate=0,FailedProduceRequestsPerSec.MeanRate=0,BytesOutPerSec.EventType="bytes",BytesRejectedPerSec.Count=0,FailedProduceRequestsPerSec.RateUnit="SECONDS",FailedProduceRequestsPerSec.EventType="requests",MessagesInPerSec.RateUnit="SECONDS",BytesInPerSec.EventType="bytes",BytesOutPerSec.RateUnit="SECONDS",BytesInPerSec.OneMinuteRate=0,FailedFetchRequestsPerSec.EventType="requests",TotalFetchRequestsPerSec.MeanRate=146.301533938701,BytesOutPerSec.FifteenMinuteRate=0,TotalProduceRequestsPerSec.MeanRate=0,BytesRejectedPerSec.FifteenMinuteRate=0,MessagesInPerSec.FiveMinuteRate=0,BytesInPerSec.Count=0,BytesRejectedPerSec.MeanRate=0,FailedFetchRequestsPerSec.MeanRate=0,FailedFetchRequestsPerSec.FiveMinuteRate=0,FailedFetchRequestsPerSec.FifteenMinuteRate=0,FailedProduceRequestsPerSec.Count=0,TotalFetchRequestsPerSec.FifteenMinuteRate=128.59314292334466,TotalFetchRequestsPerSec.OneMinuteRate=126.71551273850747,TotalFetchRequestsPerSec.Count=1353483,TotalProduceRequestsPerSec.FifteenMinuteRate=0,FailedFetchRequestsPerSec.OneMinuteRate=0,FailedFetchRequestsPerSec.Count=0,FailedProduceRequestsPerSec.FifteenMinuteRate=0,TotalFetchRequestsPerSec.FiveMinuteRate=130.8516148751592,TotalFetchRequestsPerSec.RateUnit="SECONDS",BytesRejectedPerSec.RateUnit="SECONDS",BytesInPerSec.MeanRate=0,FailedFetchRequestsPerSec.RateUnit="SECONDS",BytesRejectedPerSec.OneMinuteRate=0,BytesOutPerSec.Count=0,BytesOutPerSec.OneMinuteRate=0,MessagesInPerSec.FifteenMinuteRate=0,MessagesInPerSec.MeanRate=0,BytesInPerSec.FiveMinuteRate=0,TotalProduceRequestsPerSec.RateUnit="SECONDS",FailedProduceRequestsPerSec.OneMinuteRate=0,TotalProduceRequestsPerSec.EventType="requests",BytesRejectedPerSec.FiveMinuteRate=0,BytesRejectedPerSec.EventType="bytes",BytesOutPerSec.FiveMinuteRate=0,FailedProduceRequestsPerSec.FiveMinuteRate=0,MessagesInPerSec.Count=0,TotalProduceRequestsPerSec.FiveMinuteRate=0,TotalProduceRequestsPerSec.OneMinuteRate=0,MessagesInPerSec.EventType="messages",MessagesInPerSec.OneMinuteRate=0,TotalFetchRequestsPerSec.EventType="requests",BytesInPerSec.RateUnit="SECONDS",BytesInPerSec.FifteenMinuteRate=0,TotalProduceRequestsPerSec.Count=0 1503767532000000000
|
kafka_topic,topic=my-topic BytesOutPerSec.MeanRate=0,FailedProduceRequestsPerSec.MeanRate=0,BytesOutPerSec.EventType="bytes",BytesRejectedPerSec.Count=0,FailedProduceRequestsPerSec.RateUnit="SECONDS",FailedProduceRequestsPerSec.EventType="requests",MessagesInPerSec.RateUnit="SECONDS",BytesInPerSec.EventType="bytes",BytesOutPerSec.RateUnit="SECONDS",BytesInPerSec.OneMinuteRate=0,FailedFetchRequestsPerSec.EventType="requests",TotalFetchRequestsPerSec.MeanRate=146.301533938701,BytesOutPerSec.FifteenMinuteRate=0,TotalProduceRequestsPerSec.MeanRate=0,BytesRejectedPerSec.FifteenMinuteRate=0,MessagesInPerSec.FiveMinuteRate=0,BytesInPerSec.Count=0,BytesRejectedPerSec.MeanRate=0,FailedFetchRequestsPerSec.MeanRate=0,FailedFetchRequestsPerSec.FiveMinuteRate=0,FailedFetchRequestsPerSec.FifteenMinuteRate=0,FailedProduceRequestsPerSec.Count=0,TotalFetchRequestsPerSec.FifteenMinuteRate=128.59314292334466,TotalFetchRequestsPerSec.OneMinuteRate=126.71551273850747,TotalFetchRequestsPerSec.Count=1353483,TotalProduceRequestsPerSec.FifteenMinuteRate=0,FailedFetchRequestsPerSec.OneMinuteRate=0,FailedFetchRequestsPerSec.Count=0,FailedProduceRequestsPerSec.FifteenMinuteRate=0,TotalFetchRequestsPerSec.FiveMinuteRate=130.8516148751592,TotalFetchRequestsPerSec.RateUnit="SECONDS",BytesRejectedPerSec.RateUnit="SECONDS",BytesInPerSec.MeanRate=0,FailedFetchRequestsPerSec.RateUnit="SECONDS",BytesRejectedPerSec.OneMinuteRate=0,BytesOutPerSec.Count=0,BytesOutPerSec.OneMinuteRate=0,MessagesInPerSec.FifteenMinuteRate=0,MessagesInPerSec.MeanRate=0,BytesInPerSec.FiveMinuteRate=0,TotalProduceRequestsPerSec.RateUnit="SECONDS",FailedProduceRequestsPerSec.OneMinuteRate=0,TotalProduceRequestsPerSec.EventType="requests",BytesRejectedPerSec.FiveMinuteRate=0,BytesRejectedPerSec.EventType="bytes",BytesOutPerSec.FiveMinuteRate=0,FailedProduceRequestsPerSec.FiveMinuteRate=0,MessagesInPerSec.Count=0,TotalProduceRequestsPerSec.FiveMinuteRate=0,TotalProduceRequestsPerSec.OneMinuteRate=0,MessagesInPerSec.EventType="messages",MessagesInPerSec.OneMinuteRate=0,TotalFetchRequestsPerSec.EventType="requests",BytesInPerSec.RateUnit="SECONDS",BytesInPerSec.FifteenMinuteRate=0,TotalProduceRequestsPerSec.Count=0 1503767532000000000
|
||||||
```
|
```
|
||||||
|
|
||||||
Both `jolokia2_agent` and `jolokia2_proxy` plugins support default
|
This plugins support default configurations that apply to every `metric`
|
||||||
configurations that apply to every `metric` declaration.
|
declaration.
|
||||||
|
|
||||||
| Key | Default Value | Description |
|
| Key | Default Value | Description |
|
||||||
|---------------------------|---------------|-------------|
|
|---------------------------|---------------|-------------|
|
||||||
|
|
@ -189,19 +153,35 @@ configurations that apply to every `metric` declaration.
|
||||||
| `default_field_prefix` | _None_ | A string to prepend to the field names produced by all `metric` declarations. |
|
| `default_field_prefix` | _None_ | A string to prepend to the field names produced by all `metric` declarations. |
|
||||||
| `default_tag_prefix` | _None_ | A string to prepend to the tag names produced by all `metric` declarations. |
|
| `default_tag_prefix` | _None_ | A string to prepend to the tag names produced by all `metric` declarations. |
|
||||||
|
|
||||||
|
## Metrics
|
||||||
|
|
||||||
|
The metrics depend on the definition(s) in the `inputs.jolokia2_agent.metric`
|
||||||
|
section(s).
|
||||||
|
|
||||||
|
## Example Output
|
||||||
|
|
||||||
|
```text
|
||||||
|
jvm_memory_pool,pool_name=Compressed\ Class\ Space PeakUsage.max=1073741824,PeakUsage.committed=3145728,PeakUsage.init=0,Usage.committed=3145728,Usage.init=0,PeakUsage.used=3017976,Usage.max=1073741824,Usage.used=3017976 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=Code\ Cache PeakUsage.init=2555904,PeakUsage.committed=6291456,Usage.committed=6291456,PeakUsage.used=6202752,PeakUsage.max=251658240,Usage.used=6210368,Usage.max=251658240,Usage.init=2555904 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=G1\ Eden\ Space CollectionUsage.max=-1,PeakUsage.committed=56623104,PeakUsage.init=56623104,PeakUsage.used=53477376,Usage.max=-1,Usage.committed=49283072,Usage.used=19922944,CollectionUsage.committed=49283072,CollectionUsage.init=56623104,CollectionUsage.used=0,PeakUsage.max=-1,Usage.init=56623104 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=G1\ Old\ Gen CollectionUsage.max=1073741824,CollectionUsage.committed=0,PeakUsage.max=1073741824,PeakUsage.committed=1017118720,PeakUsage.init=1017118720,PeakUsage.used=137032208,Usage.max=1073741824,CollectionUsage.init=1017118720,Usage.committed=1017118720,Usage.init=1017118720,Usage.used=134708752,CollectionUsage.used=0 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=G1\ Survivor\ Space Usage.max=-1,Usage.init=0,CollectionUsage.max=-1,CollectionUsage.committed=7340032,CollectionUsage.used=7340032,PeakUsage.committed=7340032,Usage.committed=7340032,Usage.used=7340032,CollectionUsage.init=0,PeakUsage.max=-1,PeakUsage.init=0,PeakUsage.used=7340032 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=Metaspace PeakUsage.init=0,PeakUsage.used=21852224,PeakUsage.max=-1,Usage.max=-1,Usage.committed=22282240,Usage.init=0,Usage.used=21852224,PeakUsage.committed=22282240 1503764025000000000
|
||||||
|
```
|
||||||
|
|
||||||
## Example Configurations
|
## Example Configurations
|
||||||
|
|
||||||
* [ActiveMQ](/plugins/inputs/jolokia2/examples/activemq.conf)
|
* [ActiveMQ](/plugins/inputs/jolokia2_agent/examples/activemq.conf)
|
||||||
* [BitBucket](/plugins/inputs/jolokia2/examples/bitbucket.conf)
|
* [BitBucket](/plugins/inputs/jolokia2_agent/examples/bitbucket.conf)
|
||||||
* [Cassandra](/plugins/inputs/jolokia2/examples/cassandra.conf)
|
* [Cassandra](/plugins/inputs/jolokia2_agent/examples/cassandra.conf)
|
||||||
* [Hadoop-HDFS](/plugins/inputs/jolokia2/examples/hadoop-hdfs.conf)
|
* [Hadoop-HDFS](/plugins/inputs/jolokia2_agent/examples/hadoop-hdfs.conf)
|
||||||
* [Java JVM](/plugins/inputs/jolokia2/examples/java.conf)
|
* [Java JVM](/plugins/inputs/jolokia2_agent/examples/java.conf)
|
||||||
* [JBoss](/plugins/inputs/jolokia2/examples/jboss.conf)
|
* [JBoss](/plugins/inputs/jolokia2_agent/examples/jboss.conf)
|
||||||
* [Kafka](/plugins/inputs/jolokia2/examples/kafka.conf)
|
* [Kafka](/plugins/inputs/jolokia2_agent/examples/kafka.conf)
|
||||||
* [Kafka Connect](/plugins/inputs/jolokia2/examples/kafka-connect.conf)
|
* [Kafka Connect](/plugins/inputs/jolokia2_agent/examples/kafka-connect.conf)
|
||||||
* [Tomcat](/plugins/inputs/jolokia2/examples/tomcat.conf)
|
* [Tomcat](/plugins/inputs/jolokia2_agent/examples/tomcat.conf)
|
||||||
* [Weblogic](/plugins/inputs/jolokia2/examples/weblogic.conf)
|
* [Weblogic](/plugins/inputs/jolokia2_agent/examples/weblogic.conf)
|
||||||
* [ZooKeeper](/plugins/inputs/jolokia2/examples/zookeeper.conf)
|
* [ZooKeeper](/plugins/inputs/jolokia2_agent/examples/zookeeper.conf)
|
||||||
|
|
||||||
Please help improve this list and contribute new configuration files by opening
|
Please help improve this list and contribute new configuration files by opening
|
||||||
an issue or pull request.
|
an issue or pull request.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//go:generate ../../../../tools/readme_config_includer/generator
|
//go:generate ../../../tools/readme_config_includer/generator
|
||||||
package jolokia2_agent
|
package jolokia2_agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -10,8 +10,9 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
common "github.com/influxdata/telegraf/plugins/common/jolokia2"
|
||||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/common"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
|
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
|
||||||
|
|
@ -98,3 +99,12 @@ func (ja *JolokiaAgent) createClient(url string) (*common.Client, error) {
|
||||||
ClientConfig: ja.ClientConfig,
|
ClientConfig: ja.ClientConfig,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
inputs.Add("jolokia2_agent", func() telegraf.Input {
|
||||||
|
return &JolokiaAgent{
|
||||||
|
Metrics: []common.MetricConfig{},
|
||||||
|
DefaultFieldSeparator: ".",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package jolokia2_test
|
package jolokia2_agent_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -9,15 +11,14 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/common"
|
common "github.com/influxdata/telegraf/plugins/common/jolokia2"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/jolokia2_agent"
|
"github.com/influxdata/telegraf/plugins/inputs/jolokia2_agent"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/jolokia2_proxy"
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/influxdata/toml"
|
"github.com/influxdata/toml"
|
||||||
"github.com/influxdata/toml/ast"
|
"github.com/influxdata/toml/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestJolokia2_ScalarValues(t *testing.T) {
|
func TestScalarValues(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
urls = ["%s"]
|
urls = ["%s"]
|
||||||
|
|
@ -117,7 +118,7 @@ func TestJolokia2_ScalarValues(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_ObjectValues(t *testing.T) {
|
func TestObjectValues(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
urls = ["%s"]
|
urls = ["%s"]
|
||||||
|
|
@ -288,7 +289,7 @@ func TestJolokia2_ObjectValues(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_StatusCodes(t *testing.T) {
|
func TestStatusCodes(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
urls = ["%s"]
|
urls = ["%s"]
|
||||||
|
|
@ -343,7 +344,7 @@ func TestJolokia2_StatusCodes(t *testing.T) {
|
||||||
acc.AssertDoesNotContainMeasurement(t, "unknown")
|
acc.AssertDoesNotContainMeasurement(t, "unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_TagRenaming(t *testing.T) {
|
func TestTagRenaming(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
default_tag_prefix = "DEFAULT_PREFIX_"
|
default_tag_prefix = "DEFAULT_PREFIX_"
|
||||||
|
|
@ -400,7 +401,7 @@ func TestJolokia2_TagRenaming(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_FieldRenaming(t *testing.T) {
|
func TestFieldRenaming(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
default_field_prefix = "DEFAULT_PREFIX_"
|
default_field_prefix = "DEFAULT_PREFIX_"
|
||||||
|
|
@ -503,7 +504,7 @@ func TestJolokia2_FieldRenaming(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_MetricMbeanMatching(t *testing.T) {
|
func TestMetricMbeanMatching(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
urls = ["%s"]
|
urls = ["%s"]
|
||||||
|
|
@ -611,7 +612,7 @@ func TestJolokia2_MetricMbeanMatching(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_MetricCompaction(t *testing.T) {
|
func TestMetricCompaction(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
[jolokia2_agent]
|
[jolokia2_agent]
|
||||||
urls = ["%s"]
|
urls = ["%s"]
|
||||||
|
|
@ -694,62 +695,40 @@ func TestJolokia2_MetricCompaction(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJolokia2_ProxyTargets(t *testing.T) {
|
func TestJolokia2_ClientAuthRequest(t *testing.T) {
|
||||||
config := `
|
var username string
|
||||||
[jolokia2_proxy]
|
var password string
|
||||||
url = "%s"
|
var requests []map[string]interface{}
|
||||||
|
|
||||||
[[jolokia2_proxy.target]]
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
url = "service:jmx:rmi:///jndi/rmi://target1:9010/jmxrmi"
|
username, password, _ = r.BasicAuth()
|
||||||
|
|
||||||
[[jolokia2_proxy.target]]
|
body, _ := io.ReadAll(r.Body)
|
||||||
url = "service:jmx:rmi:///jndi/rmi://target2:9010/jmxrmi"
|
require.NoError(t, json.Unmarshal(body, &requests))
|
||||||
|
|
||||||
[[jolokia2_proxy.metric]]
|
w.WriteHeader(http.StatusOK)
|
||||||
name = "hello"
|
}))
|
||||||
mbean = "hello:foo=bar"`
|
|
||||||
|
|
||||||
response := `[{
|
|
||||||
"request": {
|
|
||||||
"type": "read",
|
|
||||||
"mbean": "hello:foo=bar",
|
|
||||||
"target": {
|
|
||||||
"url": "service:jmx:rmi:///jndi/rmi://target1:9010/jmxrmi"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"value": 123,
|
|
||||||
"status": 200
|
|
||||||
}, {
|
|
||||||
"request": {
|
|
||||||
"type": "read",
|
|
||||||
"mbean": "hello:foo=bar",
|
|
||||||
"target": {
|
|
||||||
"url": "service:jmx:rmi:///jndi/rmi://target2:9010/jmxrmi"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"value": 456,
|
|
||||||
"status": 200
|
|
||||||
}]`
|
|
||||||
|
|
||||||
server := setupServer(response)
|
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
plugin := SetupPlugin(t, fmt.Sprintf(config, server.URL))
|
|
||||||
|
plugin := SetupPlugin(t, fmt.Sprintf(`
|
||||||
|
[jolokia2_agent]
|
||||||
|
urls = ["%s/jolokia"]
|
||||||
|
username = "sally"
|
||||||
|
password = "seashore"
|
||||||
|
[[jolokia2_agent.metric]]
|
||||||
|
name = "hello"
|
||||||
|
mbean = "hello:foo=bar"
|
||||||
|
`, server.URL))
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
require.NoError(t, plugin.Gather(&acc))
|
require.NoError(t, plugin.Gather(&acc))
|
||||||
|
|
||||||
acc.AssertContainsTaggedFields(t, "hello", map[string]interface{}{
|
require.EqualValuesf(t, "sally", username, "Expected to post with username %s, but was %s", "sally", username)
|
||||||
"value": 123.0,
|
require.EqualValuesf(t, "seashore", password, "Expected to post with password %s, but was %s", "seashore", password)
|
||||||
}, map[string]string{
|
require.NotZero(t, len(requests), "Expected to post a request body, but was empty.")
|
||||||
"jolokia_proxy_url": server.URL,
|
|
||||||
"jolokia_agent_url": "service:jmx:rmi:///jndi/rmi://target1:9010/jmxrmi",
|
request := requests[0]["mbean"]
|
||||||
})
|
require.EqualValuesf(t, "hello:foo=bar", request, "Expected to query mbean %s, but was %s", "hello:foo=bar", request)
|
||||||
acc.AssertContainsTaggedFields(t, "hello", map[string]interface{}{
|
|
||||||
"value": 456.0,
|
|
||||||
}, map[string]string{
|
|
||||||
"jolokia_proxy_url": server.URL,
|
|
||||||
"jolokia_agent_url": "service:jmx:rmi:///jndi/rmi://target2:9010/jmxrmi",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFillFields(t *testing.T) {
|
func TestFillFields(t *testing.T) {
|
||||||
|
|
@ -768,9 +747,7 @@ func TestFillFields(t *testing.T) {
|
||||||
func setupServer(resp string) *httptest.Server {
|
func setupServer(resp string) *httptest.Server {
|
||||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
// Ignore the returned error as the tests will fail anyway
|
_, _ = fmt.Fprintln(w, resp)
|
||||||
//nolint:errcheck,revive
|
|
||||||
fmt.Fprintln(w, resp)
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -782,8 +759,7 @@ func SetupPlugin(t *testing.T, conf string) telegraf.Input {
|
||||||
|
|
||||||
for name := range table.Fields {
|
for name := range table.Fields {
|
||||||
object := table.Fields[name]
|
object := table.Fields[name]
|
||||||
switch name {
|
if name == "jolokia2_agent" {
|
||||||
case "jolokia2_agent":
|
|
||||||
plugin := jolokia2_agent.JolokiaAgent{
|
plugin := jolokia2_agent.JolokiaAgent{
|
||||||
Metrics: []common.MetricConfig{},
|
Metrics: []common.MetricConfig{},
|
||||||
DefaultFieldSeparator: ".",
|
DefaultFieldSeparator: ".",
|
||||||
|
|
@ -793,18 +769,6 @@ func SetupPlugin(t *testing.T, conf string) telegraf.Input {
|
||||||
t.Fatalf("Unable to parse jolokia_agent plugin config! %v", err)
|
t.Fatalf("Unable to parse jolokia_agent plugin config! %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &plugin
|
|
||||||
|
|
||||||
case "jolokia2_proxy":
|
|
||||||
plugin := jolokia2_proxy.JolokiaProxy{
|
|
||||||
Metrics: []common.MetricConfig{},
|
|
||||||
DefaultFieldSeparator: ".",
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := toml.UnmarshalTable(object.(*ast.Table), &plugin); err != nil {
|
|
||||||
t.Fatalf("Unable to parse jolokia_proxy plugin config! %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &plugin
|
return &plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
# Jolokia2 Proxy Input Plugin
|
||||||
|
|
||||||
|
The `jolokia2_proxy` input plugin reads JMX metrics from one or more _targets_
|
||||||
|
by interacting with a [Jolokia proxy](https://jolokia.org/features/proxy.html)
|
||||||
|
REST endpoint.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
```toml @sample.conf
|
||||||
|
# Read JMX metrics from a Jolokia REST proxy endpoint
|
||||||
|
[[inputs.jolokia2_proxy]]
|
||||||
|
# default_tag_prefix = ""
|
||||||
|
# default_field_prefix = ""
|
||||||
|
# default_field_separator = "."
|
||||||
|
|
||||||
|
## Proxy agent
|
||||||
|
url = "http://localhost:8080/jolokia"
|
||||||
|
# username = ""
|
||||||
|
# password = ""
|
||||||
|
# response_timeout = "5s"
|
||||||
|
|
||||||
|
## Optional origin URL to include as a header in the request. Some endpoints
|
||||||
|
## may reject an empty origin.
|
||||||
|
# origin = ""
|
||||||
|
|
||||||
|
## Optional TLS config
|
||||||
|
# tls_ca = "/var/private/ca.pem"
|
||||||
|
# tls_cert = "/var/private/client.pem"
|
||||||
|
# tls_key = "/var/private/client-key.pem"
|
||||||
|
# insecure_skip_verify = false
|
||||||
|
|
||||||
|
## Add proxy targets to query
|
||||||
|
# default_target_username = ""
|
||||||
|
# default_target_password = ""
|
||||||
|
[[inputs.jolokia2_proxy.target]]
|
||||||
|
url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
|
||||||
|
# username = ""
|
||||||
|
# password = ""
|
||||||
|
|
||||||
|
## Add metrics to read
|
||||||
|
[[inputs.jolokia2_proxy.metric]]
|
||||||
|
name = "java_runtime"
|
||||||
|
mbean = "java.lang:type=Runtime"
|
||||||
|
paths = ["Uptime"]
|
||||||
|
```
|
||||||
|
|
||||||
|
Optionally, specify TLS options for communicating with proxies:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[inputs.jolokia2_proxy]]
|
||||||
|
url = "https://proxy:8080/jolokia"
|
||||||
|
|
||||||
|
tls_ca = "/var/private/ca.pem"
|
||||||
|
tls_cert = "/var/private/client.pem"
|
||||||
|
tls_key = "/var/private/client-key.pem"
|
||||||
|
#insecure_skip_verify = false
|
||||||
|
|
||||||
|
#default_target_username = ""
|
||||||
|
#default_target_password = ""
|
||||||
|
[[inputs.jolokia2_proxy.target]]
|
||||||
|
url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
|
||||||
|
# username = ""
|
||||||
|
# password = ""
|
||||||
|
|
||||||
|
[[inputs.jolokia2_proxy.metric]]
|
||||||
|
name = "jvm_runtime"
|
||||||
|
mbean = "java.lang:type=Runtime"
|
||||||
|
paths = ["Uptime"]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Metric Configuration
|
||||||
|
|
||||||
|
Please see
|
||||||
|
[Jolokia agent documentation](../jolokia2_agent/README.md#metric-configuration).
|
||||||
|
|
||||||
|
## Metrics
|
||||||
|
|
||||||
|
The metrics depend on the definition(s) in the `inputs.jolokia2_proxy.metric`
|
||||||
|
section(s).
|
||||||
|
|
||||||
|
## Example Output
|
||||||
|
|
||||||
|
```text
|
||||||
|
jvm_memory_pool,pool_name=Compressed\ Class\ Space PeakUsage.max=1073741824,PeakUsage.committed=3145728,PeakUsage.init=0,Usage.committed=3145728,Usage.init=0,PeakUsage.used=3017976,Usage.max=1073741824,Usage.used=3017976 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=Code\ Cache PeakUsage.init=2555904,PeakUsage.committed=6291456,Usage.committed=6291456,PeakUsage.used=6202752,PeakUsage.max=251658240,Usage.used=6210368,Usage.max=251658240,Usage.init=2555904 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=G1\ Eden\ Space CollectionUsage.max=-1,PeakUsage.committed=56623104,PeakUsage.init=56623104,PeakUsage.used=53477376,Usage.max=-1,Usage.committed=49283072,Usage.used=19922944,CollectionUsage.committed=49283072,CollectionUsage.init=56623104,CollectionUsage.used=0,PeakUsage.max=-1,Usage.init=56623104 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=G1\ Old\ Gen CollectionUsage.max=1073741824,CollectionUsage.committed=0,PeakUsage.max=1073741824,PeakUsage.committed=1017118720,PeakUsage.init=1017118720,PeakUsage.used=137032208,Usage.max=1073741824,CollectionUsage.init=1017118720,Usage.committed=1017118720,Usage.init=1017118720,Usage.used=134708752,CollectionUsage.used=0 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=G1\ Survivor\ Space Usage.max=-1,Usage.init=0,CollectionUsage.max=-1,CollectionUsage.committed=7340032,CollectionUsage.used=7340032,PeakUsage.committed=7340032,Usage.committed=7340032,Usage.used=7340032,CollectionUsage.init=0,PeakUsage.max=-1,PeakUsage.init=0,PeakUsage.used=7340032 1503764025000000000
|
||||||
|
jvm_memory_pool,pool_name=Metaspace PeakUsage.init=0,PeakUsage.used=21852224,PeakUsage.max=-1,Usage.max=-1,Usage.committed=22282240,Usage.init=0,Usage.used=21852224,PeakUsage.committed=22282240 1503764025000000000
|
||||||
|
```
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//go:generate ../../../../tools/readme_config_includer/generator
|
//go:generate ../../../tools/readme_config_includer/generator
|
||||||
package jolokia2_proxy
|
package jolokia2_proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -7,8 +7,9 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
common "github.com/influxdata/telegraf/plugins/common/jolokia2"
|
||||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/jolokia2/common"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
|
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
|
||||||
|
|
@ -98,3 +99,12 @@ func (jp *JolokiaProxy) createClient() (*common.Client, error) {
|
||||||
ProxyConfig: proxyConfig,
|
ProxyConfig: proxyConfig,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
inputs.Add("jolokia2_proxy", func() telegraf.Input {
|
||||||
|
return &JolokiaProxy{
|
||||||
|
Metrics: []common.MetricConfig{},
|
||||||
|
DefaultFieldSeparator: ".",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,177 @@
|
||||||
|
package jolokia2_proxy_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf"
|
||||||
|
common "github.com/influxdata/telegraf/plugins/common/jolokia2"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/jolokia2_proxy"
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
"github.com/influxdata/toml"
|
||||||
|
"github.com/influxdata/toml/ast"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestJolokia2_ProxyTargets(t *testing.T) {
|
||||||
|
config := `
|
||||||
|
[jolokia2_proxy]
|
||||||
|
url = "%s"
|
||||||
|
|
||||||
|
[[jolokia2_proxy.target]]
|
||||||
|
url = "service:jmx:rmi:///jndi/rmi://target1:9010/jmxrmi"
|
||||||
|
|
||||||
|
[[jolokia2_proxy.target]]
|
||||||
|
url = "service:jmx:rmi:///jndi/rmi://target2:9010/jmxrmi"
|
||||||
|
|
||||||
|
[[jolokia2_proxy.metric]]
|
||||||
|
name = "hello"
|
||||||
|
mbean = "hello:foo=bar"`
|
||||||
|
|
||||||
|
response := `[{
|
||||||
|
"request": {
|
||||||
|
"type": "read",
|
||||||
|
"mbean": "hello:foo=bar",
|
||||||
|
"target": {
|
||||||
|
"url": "service:jmx:rmi:///jndi/rmi://target1:9010/jmxrmi"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": 123,
|
||||||
|
"status": 200
|
||||||
|
}, {
|
||||||
|
"request": {
|
||||||
|
"type": "read",
|
||||||
|
"mbean": "hello:foo=bar",
|
||||||
|
"target": {
|
||||||
|
"url": "service:jmx:rmi:///jndi/rmi://target2:9010/jmxrmi"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": 456,
|
||||||
|
"status": 200
|
||||||
|
}]`
|
||||||
|
|
||||||
|
server := setupServer(response)
|
||||||
|
defer server.Close()
|
||||||
|
plugin := SetupPlugin(t, fmt.Sprintf(config, server.URL))
|
||||||
|
|
||||||
|
var acc testutil.Accumulator
|
||||||
|
require.NoError(t, plugin.Gather(&acc))
|
||||||
|
|
||||||
|
acc.AssertContainsTaggedFields(t, "hello", map[string]interface{}{
|
||||||
|
"value": 123.0,
|
||||||
|
}, map[string]string{
|
||||||
|
"jolokia_proxy_url": server.URL,
|
||||||
|
"jolokia_agent_url": "service:jmx:rmi:///jndi/rmi://target1:9010/jmxrmi",
|
||||||
|
})
|
||||||
|
acc.AssertContainsTaggedFields(t, "hello", map[string]interface{}{
|
||||||
|
"value": 456.0,
|
||||||
|
}, map[string]string{
|
||||||
|
"jolokia_proxy_url": server.URL,
|
||||||
|
"jolokia_agent_url": "service:jmx:rmi:///jndi/rmi://target2:9010/jmxrmi",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJolokia2_ClientProxyAuthRequest(t *testing.T) {
|
||||||
|
var requests []map[string]interface{}
|
||||||
|
|
||||||
|
var username string
|
||||||
|
var password string
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
username, password, _ = r.BasicAuth()
|
||||||
|
|
||||||
|
body, _ := io.ReadAll(r.Body)
|
||||||
|
require.NoError(t, json.Unmarshal(body, &requests))
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, err := fmt.Fprintf(w, "[]")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
plugin := SetupPlugin(t, fmt.Sprintf(`
|
||||||
|
[jolokia2_proxy]
|
||||||
|
url = "%s/jolokia"
|
||||||
|
username = "sally"
|
||||||
|
password = "seashore"
|
||||||
|
|
||||||
|
[[jolokia2_proxy.target]]
|
||||||
|
url = "service:jmx:rmi:///jndi/rmi://target:9010/jmxrmi"
|
||||||
|
username = "jack"
|
||||||
|
password = "benimble"
|
||||||
|
|
||||||
|
[[jolokia2_proxy.metric]]
|
||||||
|
name = "hello"
|
||||||
|
mbean = "hello:foo=bar"
|
||||||
|
`, server.URL))
|
||||||
|
|
||||||
|
var acc testutil.Accumulator
|
||||||
|
require.NoError(t, plugin.Gather(&acc))
|
||||||
|
require.EqualValuesf(t, "sally", username, "Expected to post with username %s, but was %s", "sally", username)
|
||||||
|
require.EqualValuesf(t, "seashore", password, "Expected to post with password %s, but was %s", "seashore", password)
|
||||||
|
require.NotZero(t, len(requests), "Expected to post a request body, but was empty.")
|
||||||
|
|
||||||
|
request := requests[0]
|
||||||
|
expected := "hello:foo=bar"
|
||||||
|
require.EqualValuesf(t, expected, request["mbean"], "Expected to query mbean %s, but was %s", expected, request["mbean"])
|
||||||
|
|
||||||
|
target, ok := request["target"].(map[string]interface{})
|
||||||
|
require.True(t, ok, "Expected a proxy target, but was empty.")
|
||||||
|
|
||||||
|
expected = "service:jmx:rmi:///jndi/rmi://target:9010/jmxrmi"
|
||||||
|
require.Equalf(t, expected, target["url"], "Expected proxy target url %s, but was %s", expected, target["url"])
|
||||||
|
expected = "jack"
|
||||||
|
require.Equalf(t, expected, target["user"], "Expected proxy target username %s, but was %s", expected, target["user"])
|
||||||
|
expected = "benimble"
|
||||||
|
require.Equalf(t, expected, target["password"], "Expected proxy target username %s, but was %s", expected, target["password"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFillFields(t *testing.T) {
|
||||||
|
complexPoint := map[string]interface{}{"Value": []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
|
||||||
|
scalarPoint := []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
|
||||||
|
results := map[string]interface{}{}
|
||||||
|
common.NewPointBuilder(common.Metric{Name: "test", Mbean: "complex"}, []string{"this", "that"}, "/").FillFields("", complexPoint, results)
|
||||||
|
require.Equal(t, map[string]interface{}{}, results)
|
||||||
|
|
||||||
|
results = map[string]interface{}{}
|
||||||
|
common.NewPointBuilder(common.Metric{Name: "test", Mbean: "scalar"}, []string{"this", "that"}, "/").FillFields("", scalarPoint, results)
|
||||||
|
require.Equal(t, map[string]interface{}{}, results)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupServer(resp string) *httptest.Server {
|
||||||
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
// Ignore the returned error as the tests will fail anyway
|
||||||
|
//nolint:errcheck,revive
|
||||||
|
fmt.Fprintln(w, resp)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetupPlugin(t *testing.T, conf string) telegraf.Input {
|
||||||
|
table, err := toml.Parse([]byte(conf))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to parse config! %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for name := range table.Fields {
|
||||||
|
object := table.Fields[name]
|
||||||
|
if name == "jolokia2_proxy" {
|
||||||
|
plugin := jolokia2_proxy.JolokiaProxy{
|
||||||
|
Metrics: []common.MetricConfig{},
|
||||||
|
DefaultFieldSeparator: ".",
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := toml.UnmarshalTable(object.(*ast.Table), &plugin); err != nil {
|
||||||
|
t.Fatalf("Unable to parse jolokia_proxy plugin config! %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &plugin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue