2017-09-27 00:34:46 +00:00
|
|
|
package jolokia2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/influxdata/telegraf"
|
2018-05-12 00:47:38 +00:00
|
|
|
"github.com/influxdata/telegraf/internal"
|
2018-05-04 23:33:23 +00:00
|
|
|
"github.com/influxdata/telegraf/internal/tls"
|
2017-09-27 00:34:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type JolokiaProxy struct {
|
|
|
|
DefaultFieldPrefix string
|
|
|
|
DefaultFieldSeparator string
|
|
|
|
DefaultTagPrefix string
|
|
|
|
|
|
|
|
URL string `toml:"url"`
|
|
|
|
DefaultTargetPassword string
|
|
|
|
DefaultTargetUsername string
|
|
|
|
Targets []JolokiaProxyTargetConfig `toml:"target"`
|
|
|
|
|
2018-05-04 23:33:23 +00:00
|
|
|
Username string
|
|
|
|
Password string
|
2018-05-12 00:47:38 +00:00
|
|
|
ResponseTimeout internal.Duration `toml:"response_timeout"`
|
2018-05-04 23:33:23 +00:00
|
|
|
tls.ClientConfig
|
2017-09-27 00:34:46 +00:00
|
|
|
|
|
|
|
Metrics []MetricConfig `toml:"metric"`
|
|
|
|
client *Client
|
|
|
|
gatherer *Gatherer
|
|
|
|
}
|
|
|
|
|
|
|
|
type JolokiaProxyTargetConfig struct {
|
|
|
|
URL string `toml:"url"`
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (jp *JolokiaProxy) SampleConfig() string {
|
|
|
|
return `
|
|
|
|
# default_tag_prefix = ""
|
|
|
|
# default_field_prefix = ""
|
|
|
|
# default_field_separator = "."
|
|
|
|
|
|
|
|
## Proxy agent
|
|
|
|
url = "http://localhost:8080/jolokia"
|
|
|
|
# username = ""
|
|
|
|
# password = ""
|
|
|
|
# response_timeout = "5s"
|
|
|
|
|
2018-05-04 23:33:23 +00:00
|
|
|
## Optional TLS config
|
|
|
|
# tls_ca = "/var/private/ca.pem"
|
|
|
|
# tls_cert = "/var/private/client.pem"
|
|
|
|
# tls_key = "/var/private/client-key.pem"
|
2017-09-27 00:34:46 +00:00
|
|
|
# insecure_skip_verify = false
|
|
|
|
|
|
|
|
## Add proxy targets to query
|
|
|
|
# default_target_username = ""
|
|
|
|
# default_target_password = ""
|
2018-04-23 22:06:26 +00:00
|
|
|
[[inputs.jolokia2_proxy.target]]
|
2017-09-27 00:34:46 +00:00
|
|
|
url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
|
2018-04-23 22:06:26 +00:00
|
|
|
# username = ""
|
|
|
|
# password = ""
|
2017-09-27 00:34:46 +00:00
|
|
|
|
|
|
|
## Add metrics to read
|
2018-04-23 22:06:26 +00:00
|
|
|
[[inputs.jolokia2_proxy.metric]]
|
2017-09-27 00:34:46 +00:00
|
|
|
name = "java_runtime"
|
|
|
|
mbean = "java.lang:type=Runtime"
|
|
|
|
paths = ["Uptime"]
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (jp *JolokiaProxy) Description() string {
|
|
|
|
return "Read JMX metrics from a Jolokia REST proxy endpoint"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (jp *JolokiaProxy) Gather(acc telegraf.Accumulator) error {
|
|
|
|
if jp.gatherer == nil {
|
|
|
|
jp.gatherer = 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() []Metric {
|
|
|
|
var metrics []Metric
|
|
|
|
|
|
|
|
for _, config := range jp.Metrics {
|
|
|
|
metrics = append(metrics, NewMetric(config,
|
|
|
|
jp.DefaultFieldPrefix, jp.DefaultFieldSeparator, jp.DefaultTagPrefix))
|
|
|
|
}
|
|
|
|
|
|
|
|
return metrics
|
|
|
|
}
|
|
|
|
|
|
|
|
func (jp *JolokiaProxy) createClient() (*Client, error) {
|
|
|
|
proxyConfig := &ProxyConfig{
|
|
|
|
DefaultTargetUsername: jp.DefaultTargetUsername,
|
|
|
|
DefaultTargetPassword: jp.DefaultTargetPassword,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, target := range jp.Targets {
|
|
|
|
proxyConfig.Targets = append(proxyConfig.Targets, ProxyTargetConfig{
|
|
|
|
URL: target.URL,
|
|
|
|
Username: target.Username,
|
|
|
|
Password: target.Password,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewClient(jp.URL, &ClientConfig{
|
2018-05-04 23:33:23 +00:00
|
|
|
Username: jp.Username,
|
|
|
|
Password: jp.Password,
|
2018-05-12 00:47:38 +00:00
|
|
|
ResponseTimeout: jp.ResponseTimeout.Duration,
|
2018-05-04 23:33:23 +00:00
|
|
|
ClientConfig: jp.ClientConfig,
|
|
|
|
ProxyConfig: proxyConfig,
|
2017-09-27 00:34:46 +00:00
|
|
|
})
|
|
|
|
}
|