Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
104
plugins/inputs/jolokia2_proxy/README.md
Normal file
104
plugins/inputs/jolokia2_proxy/README.md
Normal file
|
@ -0,0 +1,104 @@
|
|||
# Jolokia2 Proxy Input Plugin
|
||||
|
||||
This plugin reads JMX metrics from one or more _targets_ by interacting with a
|
||||
[Jolokia proxy][jolokia_proxy] REST endpoint.
|
||||
|
||||
⭐ Telegraf v1.5.0
|
||||
🏷️ applications, network
|
||||
💻 all
|
||||
|
||||
[jolokia_proxy]: https://jolokia.org/features/proxy.html
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## 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
|
||||
```
|
105
plugins/inputs/jolokia2_proxy/jolokia2_proxy.go
Normal file
105
plugins/inputs/jolokia2_proxy/jolokia2_proxy.go
Normal file
|
@ -0,0 +1,105 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package jolokia2_proxy
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"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/inputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
type JolokiaProxy struct {
|
||||
DefaultFieldPrefix string `toml:"default_field_prefix"`
|
||||
DefaultFieldSeparator string `toml:"default_field_separator"`
|
||||
DefaultTagPrefix string `toml:"default_tag_prefix"`
|
||||
|
||||
URL string `toml:"url"`
|
||||
DefaultTargetPassword string `toml:"default_target_password"`
|
||||
DefaultTargetUsername string `toml:"default_target_username"`
|
||||
Targets []jolokiaProxyTargetConfig `toml:"target"`
|
||||
|
||||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
Origin string `toml:"origin"`
|
||||
ResponseTimeout config.Duration `toml:"response_timeout"`
|
||||
tls.ClientConfig
|
||||
|
||||
Metrics []common.MetricConfig `toml:"metric"`
|
||||
client *common.Client
|
||||
gatherer *common.Gatherer
|
||||
}
|
||||
|
||||
type jolokiaProxyTargetConfig struct {
|
||||
URL string `toml:"url"`
|
||||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
}
|
||||
|
||||
func (*JolokiaProxy) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (jp *JolokiaProxy) Gather(acc telegraf.Accumulator) error {
|
||||
if jp.gatherer == nil {
|
||||
jp.gatherer = common.NewGatherer(jp.createMetrics())
|
||||
}
|
||||
|
||||
if jp.client == nil {
|
||||
client, err := jp.createClient()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jp.client = client
|
||||
}
|
||||
|
||||
return jp.gatherer.Gather(jp.client, acc)
|
||||
}
|
||||
|
||||
func (jp *JolokiaProxy) createMetrics() []common.Metric {
|
||||
metrics := make([]common.Metric, 0, len(jp.Metrics))
|
||||
for _, metricConfig := range jp.Metrics {
|
||||
metrics = append(metrics, common.NewMetric(metricConfig, jp.DefaultFieldPrefix, jp.DefaultFieldSeparator, jp.DefaultTagPrefix))
|
||||
}
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
func (jp *JolokiaProxy) createClient() (*common.Client, error) {
|
||||
proxyConfig := &common.ProxyConfig{
|
||||
DefaultTargetUsername: jp.DefaultTargetUsername,
|
||||
DefaultTargetPassword: jp.DefaultTargetPassword,
|
||||
}
|
||||
|
||||
for _, target := range jp.Targets {
|
||||
proxyConfig.Targets = append(proxyConfig.Targets, common.ProxyTargetConfig{
|
||||
URL: target.URL,
|
||||
Username: target.Username,
|
||||
Password: target.Password,
|
||||
})
|
||||
}
|
||||
|
||||
return common.NewClient(jp.URL, &common.ClientConfig{
|
||||
Username: jp.Username,
|
||||
Password: jp.Password,
|
||||
ResponseTimeout: time.Duration(jp.ResponseTimeout),
|
||||
ClientConfig: jp.ClientConfig,
|
||||
ProxyConfig: proxyConfig,
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("jolokia2_proxy", func() telegraf.Input {
|
||||
return &JolokiaProxy{
|
||||
DefaultFieldSeparator: ".",
|
||||
}
|
||||
})
|
||||
}
|
194
plugins/inputs/jolokia2_proxy/jolokia2_proxy_test.go
Normal file
194
plugins/inputs/jolokia2_proxy/jolokia2_proxy_test.go
Normal file
|
@ -0,0 +1,194 @@
|
|||
package jolokia2_proxy_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/toml"
|
||||
"github.com/influxdata/toml/ast"
|
||||
"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"
|
||||
)
|
||||
|
||||
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, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &requests); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if _, err = fmt.Fprintf(w, "[]"); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}))
|
||||
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.NotEmpty(t, 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, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
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{
|
||||
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
|
||||
}
|
35
plugins/inputs/jolokia2_proxy/sample.conf
Normal file
35
plugins/inputs/jolokia2_proxy/sample.conf
Normal file
|
@ -0,0 +1,35 @@
|
|||
# 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"]
|
Loading…
Add table
Add a link
Reference in a new issue