Skip to content

Commit

Permalink
[com.influxdata.telegraf] Add Jolokia2 input plugin (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
srueg authored Dec 13, 2024
1 parent 63cbe07 commit 267ad65
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/com.influxdata.telegraf/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ dependencies {
}

package {
version = "1.3.0"
version = "1.4.0"
}
23 changes: 14 additions & 9 deletions packages/com.influxdata.telegraf/Telegraf.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@
@ModuleInfo { minPklVersion = "0.25.0" }
open module com.influxdata.telegraf.Telegraf

import "plugins/Plugin.pkl"
import "plugins/inputs/CpuInput.pkl"
import "plugins/inputs/DiskInput.pkl"
import "plugins/inputs/ExecInput.pkl"
import "plugins/inputs/FileInput.pkl"
import "plugins/inputs/HttpInput.pkl"
import "plugins/inputs/SocketListenerInput.pkl"
import "plugins/inputs/PrometheusInput.pkl"
import "plugins/inputs/DiskInput.pkl"
import "plugins/inputs/CpuInput.pkl"
import "plugins/inputs/Jolokia2AgentInput.pkl"
import "plugins/inputs/NetInput.pkl"
import "plugins/inputs/ExecInput.pkl"
import "plugins/inputs/PrometheusInput.pkl"
import "plugins/inputs/SocketListenerInput.pkl"
import "plugins/inputs/SolrInput.pkl"
import "plugins/outputs/FileOutput.pkl"
import "plugins/outputs/DiscardOutput.pkl"
import "plugins/outputs/PrometheusClientOutput.pkl"
import "plugins/outputs/FileOutput.pkl"
import "plugins/outputs/OpenTelemetryOutput.pkl"
import "plugins/outputs/PrometheusClientOutput.pkl"
import "plugins/processors/StarlarkProcessor.pkl"

import "plugins/Plugin.pkl"

/// Telegraf has a few options you can configure under the [agent] section of the config.
agent: AgentConfig?

Expand Down Expand Up @@ -142,6 +142,11 @@ open class Inputs {
/// The [Solr input plugin](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/solr/README.md)
/// gathers metrics from one or more Solr servers
solr: Listing<SolrInput>?

/// [Jolokia Agent Input Plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/jolokia2_agent)
///
/// Reads JMX metrics from one or more Jolokia agent REST endpoints.
jolokia2_agent: Listing<Jolokia2AgentInput>?
}

open class Processors {
Expand Down
46 changes: 46 additions & 0 deletions packages/com.influxdata.telegraf/examples/InputJolokiaAgent.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
amends "../Telegraf.pkl"

agent {
collection_jitter = 0.s
debug = true
flush_interval = 30.s
flush_jitter = 0.s
interval = 30.s
}

inputs {
jolokia2_agent {
new {
urls {
"http://localhost:7883"
}
response_timeout = 3.s
tls_cert = "/var/private/client.pem"
tls_key = "/var/private/client-key.pem"
metric {
new {
name = "java_runtime"
mbean = "java.lang:type=Runtime"
paths {
"Uptime"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
/// [Jolokia Agent Input Plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/jolokia2_agent)
///
/// Reads JMX metrics from one or more Jolokia agent REST endpoints.
/// See [docs](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/jolokia2_agent/README.md) for examples.
module com.influxdata.telegraf.plugins.inputs.Jolokia2AgentInput

extends "Input.pkl"

/// List of endpoints to read JMX metrics from a Jolokia REST agent.
urls: Listing<String>(length > 0)

username: String?
password: String?

/// Origin URL to include as a header in the request.
origin: String?

response_timeout: Duration?

tls_ca: String?
tls_cert: String?
tls_key: String?
insecure_skip_verify: Boolean?

/// String to prepend to the field names produced by all metric declarations.
default_field_prefix: String?

/// Character to use to join Mbean attributes when creating fields.
default_field_separator: String?

/// String to prepend to the tag names produced by all metric declarations
default_tag_prefix: String?

/// Metrics to collect from the Jolokia agent.
///
/// Each metric declaration generates a Jolokia request to fetch telemetry from a JMX MBean.
metric: Listing<MetricConfig>

class MetricConfig {
/// Metric name.
name: String

/// The object name of a JMX MBean.
///
/// MBean property-key values can contain a wildcard `*`, allowing to fetch multiple MBeans with one declaration.
mbean: String

/// List of MBean attributes to read.
paths: Listing<String>

/// String to set as the name of the field produced by this metric.
///
/// This can contain substitutions.
field_name: String?

/// String to prepend to the field names produced by this metric declaration.
///
/// This can contain substitutions.
field_prefix: String?

/// Character to use to join Mbean attributes when creating fields.
field_separator: String?

/// String to prepend to the tag names produced by this metric declaration.
tag_prefix: String?

/// List of MBean property-key names to convert into tags.
///
/// The property-key name becomes the tag name, while the property-key value becomes the tag value.
tag_keys: Listing<String>
}
21 changes: 21 additions & 0 deletions packages/com.influxdata.telegraf/tests/Telegraf.pkl-expected.pcf
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
examples {
["InputJolokiaAgent.toml"] {
"""
[agent]
interval = "30s"
collection_jitter = "0s"
flush_interval = "30s"
flush_jitter = "0s"
debug = true

[[inputs.jolokia2_agent]]
urls = [ "http://localhost:7883" ]
response_timeout = "3s"
tls_cert = "/var/private/client.pem"
tls_key = "/var/private/client-key.pem"

[[inputs.jolokia2_agent.metric]]
name = "java_runtime"
mbean = "java.lang:type=Runtime"
paths = [ "Uptime" ]
"""
}
["opentelemetry-output.toml"] {
"""
[[outputs.opentelemetry]]
Expand Down

0 comments on commit 267ad65

Please sign in to comment.