Skip to content

Commit 7a09bf9

Browse files
Adopt OpenTelemetry 1.0.0-alpha (#32)
* Update JMX Metric Gather to use 1.0.0 * Correct JMX Metric Gatherer readme for 1.0.0
1 parent ee0c414 commit 7a09bf9

29 files changed

+861
-720
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = 'OpenTelemetry Contrib libraries and utilities for the JVM'
99

1010
allprojects {
1111
group = 'io.opentelemetry.contrib'
12-
version = '0.0.1-SNAPSHOT'
12+
version = '1.0.0-alpha-SNAPSHOT'
1313

1414
apply from: "$rootDir/gradle/spotless.gradle"
1515
apply from: "$rootDir/gradle/dependencies.gradle"

contrib/jmx-metrics/README.md

Lines changed: 89 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,83 @@
11
# JMX Metric Gatherer
22

33
This utility provides an easy framework for gathering and reporting metrics based on queried
4-
MBeans from a JMX server. It loads a custom Groovy script and establishes a helpful, bound `otel`
5-
object with methods for obtaining MBeans and constructing synchronous OpenTelemetry instruments:
4+
MBeans from a JMX server. It loads an included or custom Groovy script and establishes a helpful,
5+
bound `otel` object with methods for obtaining MBeans and constructing OpenTelemetry instruments:
66

77
### Usage
88

9+
The JMX Metric Gatherer is intended to be run as an uber jar and configured with properties from the command line,
10+
properties file, and stdin (`-`). Its metric-gathering scripts are specified by supported `otel.jmx.target.system`
11+
values or a `otel.jmx.groovy.script` path to run your own.
12+
913
```bash
10-
$ java -D<otel.jmx.property=value> -jar opentelemetry-java-contrib-jmx-metrics-<version>.jar [-config {optional_config.properties, '-'}]
14+
$ java -D<otel.jmx.property=value> -jar opentelemetry-java-contrib-jmx-metrics-<version>.jar [-config {session.properties, '-'}]
1115
```
1216

13-
##### `optional_config.properties` example
17+
##### `session.properties`
1418

1519
```properties
1620
otel.jmx.service.url = service:jmx:rmi:///jndi/rmi://<my-jmx-host>:<my-jmx-port>/jmxrmi
1721
otel.jmx.target.system = jvm,kafka
1822
otel.jmx.interval.milliseconds = 5000
19-
otel.exporter = otlp
20-
otel.otlp.endpoint = my-opentelemetry-collector:55680
2123
otel.jmx.username = my-username
2224
otel.jmx.password = my-password
25+
26+
otel.metrics.exporter = otlp
27+
otel.exporter.otlp.endpoint = http://my-opentelemetry-collector:55680
2328
```
2429

25-
##### `script.groovy` example
30+
As configured in this example, the metric gatherer will establish an MBean server connection using the
31+
specified `otel.jmx.service.url` (required) and credentials and configure an OTLP gRPC metrics exporter reporting to
32+
`otel.exporter.otlp.endpoint`. After loading the included JVM and Kafka metric-gathering scripts determined by
33+
the comma-separated list in `otel.jmx.target.system`, it will then run the scripts on the desired interval
34+
length of `otel.jmx.interval.milliseconds` and export the resulting metrics.
35+
36+
For custom metrics and unsupported targets, you can provide your own MBean querying scripts to produce
37+
OpenTelemetry instruments:
38+
39+
```bash
40+
$ java -Dotel.jmx.groovy.script=./script.groovy -jar opentelemetry-java-contrib-jmx-metrics-<version>.jar [-config {optional.properties, '-'}]
41+
```
42+
43+
##### `script.groovy`
2644

2745
```groovy
28-
def storageLoadMBean = otel.mbean("org.apache.cassandra.metrics:type=Storage,name=Load")
29-
otel.instrument(storageLoadMBean, "cassandra.storage.load",
30-
"Size, in bytes, of the on disk data size this node manages",
46+
// Query the target JMX server for the desired MBean and create a helper representing the first result
47+
def loadMBean = otel.mbean("io.example.service:type=MyType,name=Load")
48+
49+
// Create a LongValueObserver whose updater will set the instrument value to the
50+
// loadMBean's most recent `Count` attribute's long value. The instrument will have a
51+
// name of "my.type.load" and the specified description and unit, respectively.
52+
otel.instrument(
53+
loadMBean, "my.type.load",
54+
"Load, in bytes, of the service of MyType",
3155
"By", "Count", otel.&longValueObserver
3256
)
3357
```
3458

35-
As configured in the example, this metric gatherer will configure an otlp gRPC metric exporter
36-
at the `otel.otlp.endpoint` and establish an MBean server connection using the
37-
provided `otel.jmx.service.url`. After loading the included metric gathering scripts specified by the
38-
comma-separated list in `otel.jmx.target.system`, it will then run the scripts on the specified
39-
`otel.jmx.interval.milliseconds` and export the resulting metrics.
59+
The specified `script.groovy` file will be run on the desired `otel.jmx.interval.milliseconds` (10000 by default),
60+
resulting in an exported `my.type.load` instrument with the observed value of the desired MBean's `Count`
61+
attribute as queried in each interval.
62+
63+
### Target Systems
64+
65+
The JMX Metric Gatherer provides built in metric producing Groovy scripts for supported target systems
66+
capable of being specified via the `otel.jmx.target.system` property as a comma-separated list. This property is
67+
mutually exclusive with `otel.jmx.groovy.script`. The currently supported target systems are:
68+
69+
| `otel.jmx.target.system` |
70+
| ------------------------ |
71+
| [`jvm`](./docs/target-systems/jvm.md) |
72+
| [`cassandra`](./docs/target-systems/cassandra.md) |
73+
| [`kafka`](./docs/target-systems/kafka.md) |
74+
| [`kafka-consumer`](./docs/target-systems/kafka-consumer.md) |
75+
| [`kafka-producer`](./docs/target-systems/kafka-producer.md) |
4076

4177
### JMX Query Helpers
4278

4379
- `otel.queryJmx(String objectNameStr)`
44-
- This method will query the connected JMX application for the given `objectName`, which can
80+
- This method will query the connected JMX application for the given `objectNameStr`, which can
4581
include wildcards. The return value will be a sorted `List<GroovyMBean>` of zero or more
4682
[`GroovyMBean` objects](http://docs.groovy-lang.org/latest/html/api/groovy/jmx/GroovyMBean.html),
4783
which are conveniently wrapped to make accessing attributes on the MBean simple.
@@ -56,18 +92,21 @@ comma-separated list in `otel.jmx.target.system`, it will then run the scripts o
5692
- `otel.mbean(String objectNameStr)`
5793
- This method will query for the given `objectNameStr` using `otel.queryJmx()` as previously described,
5894
but returns an `MBeanHelper` instance representing the alphabetically first matching MBean for usage by
59-
subsequent `InstrumentHelper` instances (available via `otel.instrument()`) as described below.
95+
subsequent `InstrumentHelper` instances (available via `otel.instrument()`) as described below. It is
96+
intended to be used in cases where your `objectNameStr` will return a single element `List<GroovyMBean>`
97+
to avoid redundant item access.
6098

6199
- `otel.mbeans(String objectNameStr)`
62100
- This method will query for the given `objectNameStr` using `otel.queryJmx()` as previously described,
63101
but returns an `MBeanHelper` instance representing all matching MBeans for usage by subsequent `InstrumentHelper`
64-
instances (available via `otel.instrument()`) as described below.
102+
instances (available via `otel.instrument()`) as described below. It is intended to be used in cases
103+
where your given `objectNameStr` can return a multiple element `List<GroovyMBean>`.
65104

66105
- `otel.instrument(MBeanHelper mBeanHelper, String instrumentName, String description, String unit, Map<String, Closure> labelFuncs, String attribute, Closure instrument)`
67106
- This method provides the ability to easily create and automatically update instrument instances from an
68-
`MBeanHelper`'s underlying MBean instances via an OpenTelemetry instrument helper method pointer as described below.
69-
- The method parameters map to those of the instrument helpers, while the new `Map<String, Closure> labelFuncs` will
70-
be used to specify updated instrument labels that have access to the inspected MBean:
107+
`MBeanHelper`'s underlying MBeans via an OpenTelemetry instrument helper method pointer as described below.
108+
- The method parameters map to those of the instrument helpers, while the additional `Map<String, Closure> labelFuncs`
109+
will be used to specify updated instrument labels that have access to the inspected MBean:
71110

72111
```groovy
73112
// This example's resulting datapoint(s) will have Labels consisting of the specified key
@@ -110,44 +149,42 @@ aren't desired upon invocation.
110149

111150
### OpenTelemetry Asynchronous Instrument Helpers
112151

113-
- `otel.doubleSumObserver(String name, String description, String unit)`
152+
- `otel.doubleSumObserver(String name, String description, String unit, Closure updater)`
114153

115-
- `otel.longSumObserver(String name, String description, String unit)`
154+
- `otel.longSumObserver(String name, String description, String unit, Closure updater)`
116155

117-
- `otel.doubleUpDownSumObserver(String name, String description, String unit)`
156+
- `otel.doubleUpDownSumObserver(String name, String description, String unit, Closure updater)`
118157

119-
- `otel.longUpDownSumObserver(String name, String description, String unit)`
158+
- `otel.longUpDownSumObserver(String name, String description, String unit, Closure updater)`
120159

121-
- `otel.doubleValueObserver(String name, String description, String unit)`
160+
- `otel.doubleValueObserver(String name, String description, String unit, Closure updater)`
122161

123-
- `otel.longValueObserver(String name, String description, String unit)`
162+
- `otel.longValueObserver(String name, String description, String unit, Closure updater)`
124163

125164
These methods will return a new or previously registered instance of the applicable metric
126165
instruments. Each one provides two additional signatures where unit and description aren't
127166
desired upon invocation.
128167

129-
- `otel.<meterMethod>(String name, String description)` - `unit` is "1".
130-
131-
- `otel.<meterMethod>(String name)` - `description` is empty string and `unit` is "1".
168+
- `otel.<meterMethod>(String name, String description, Closure updater)` - `unit` is "1".
132169

133-
### Compatibility
170+
- `otel.<meterMethod>(String name, Closure updater)` - `description` is empty string and `unit` is "1".
134171

135-
This metric extension supports Java 7+, though SASL is only supported where
136-
`com.sun.security.sasl.Provider` is available.
172+
Though asynchronous instrument updaters are exclusively set by their builders in the OpenTelemetry API,
173+
the JMX Metric Gatherer asynchronous instrument helpers allow using the specified updater Closure for
174+
each instrument as run on the desired interval:
137175

138-
### Target Systems
176+
```groovy
177+
def loadMBean = otel.mbean("io.example.service:type=MyType,name=Load")
178+
otel.longValueObserver(
179+
"my.type.load", "Load, in bytes, of the service of MyType", "By",
180+
{ longResult -> longResult.observe(storageLoadMBean.getAttribute("Count")) }
181+
)
182+
```
139183

140-
The JMX Metric Gatherer also provides built in metric producing Groovy scripts for supported target systems
141-
capable of being specified via the `otel.jmx.target.system` property as a comma-separated list (mutually exclusive with
142-
`otel.jmx.groovy.script`). The currently available target systems are:
184+
### Compatibility
143185

144-
| `otel.jmx.target.system` |
145-
| ------------------------ |
146-
| [`jvm`](./docs/target-systems/jvm.md) |
147-
| [`cassandra`](./docs/target-systems/cassandra.md) |
148-
| [`kafka`](./docs/target-systems/kafka.md) |
149-
| [`kafka-consumer`](./docs/target-systems/kafka-consumer.md) |
150-
| [`kafka-producer`](./docs/target-systems/kafka-producer.md) |
186+
This metric extension supports Java 8+, though SASL is only supported where
187+
`com.sun.security.sasl.Provider` is available.
151188

152189
### Configuration
153190

@@ -161,19 +198,18 @@ file contents can also be provided via stdin on startup when using `-config -` a
161198
| `otel.jmx.groovy.script` | if not using `otel.jmx.target.system` | The path for the desired Groovy script. |
162199
| `otel.jmx.target.system` | if not using `otel.jmx.groovy.script` | A comma-separated list of the supported target applications with built in Groovy scripts. |
163200
| `otel.jmx.interval.milliseconds` | no | How often, in milliseconds, the Groovy script should be run and its resulting metrics exported. 10000 by default. |
164-
| `otel.exporter` | no | The type of metric exporter to use: (`otlp`, `prometheus`, `inmemory`, `logging`). `logging` by default. |
165-
| `otel.exporter.otlp.endpoint` | no | The otlp exporter endpoint to use, Required for `otlp`. |
166-
| `otel.exporter.otlp.metric.timeout` | no | The otlp exporter request timeout (in milliseconds). Default is 1000. |
167-
| `otel.exporter.otlp.use.tls` | no | Whether to use TLS for otlp channel. Setting any value evaluates to `true`. |
168-
| `otel.exporter.otlp.metadata` | no | Any headers to include in otlp exporter metric submissions. Of the form `'header1=value1;header2=value2'` |
169-
| `otel.exporter.prometheus.host` | no | The prometheus collector server host. Default is `localhost`. |
170-
| `otel.exporter.prometheus.port` | no | The prometheus collector server port. Default is `9090`. |
171201
| `otel.jmx.username` | no | Username for JMX authentication, if applicable. |
172202
| `otel.jmx.password` | no | Password for JMX authentication, if applicable. |
203+
| `otel.jmx.remote.profile` | no | Supported JMX remote profiles are TLS in combination with SASL profiles: SASL/PLAIN, SASL/DIGEST-MD5 and SASL/CRAM-MD5. Thus valid `jmxRemoteProfiles` values are: `SASL/PLAIN`, `SASL/DIGEST-MD5`, `SASL/CRAM-MD5`, `TLS SASL/PLAIN`, `TLS SASL/DIGEST-MD5` and `TLS SASL/CRAM-MD5`. |
204+
| `otel.jmx.realm` | no | The realm is required by profile SASL/DIGEST-MD5. |
205+
| `otel.metrics.exporter` | no | The type of metric exporter to use: (`otlp`, `prometheus`, `inmemory`, `logging`). `logging` by default. |
206+
| `otel.exporter.otlp.endpoint` | no | The otlp exporter endpoint to use, Required for `otlp`. |
207+
| `otel.exporter.otlp.headers` | no | Any headers to include in otlp exporter metric submissions. Of the form `header1=value1,header2=value2` |
208+
| `otel.exporter.otlp.timeout` | no | The otlp exporter request timeout (in milliseconds). Default is 1000. |
209+
| `otel.exporter.prometheus.host` | no | The prometheus collector server host. Default is `0.0.0.0`. |
210+
| `otel.exporter.prometheus.port` | no | The prometheus collector server port. Default is `9464`. |
173211
| `javax.net.ssl.keyStore` | no | The key store path is required if client authentication is enabled on the target JVM. |
174212
| `javax.net.ssl.keyStorePassword` | no | The key store file password if required. |
175213
| `javax.net.ssl.keyStoreType` | no | The key store type. |
176214
| `javax.net.ssl.trustStore` | no | The trusted store path if the TLS profile is required. |
177215
| `javax.net.ssl.trustStorePassword` | no | The trust store file password if required. |
178-
| `otel.jmx.remote.profile` | no | Supported JMX remote profiles are TLS in combination with SASL profiles: SASL/PLAIN, SASL/DIGEST-MD5 and SASL/CRAM-MD5. Thus valid `jmxRemoteProfiles` values are: `SASL/PLAIN`, `SASL/DIGEST-MD5`, `SASL/CRAM-MD5`, `TLS SASL/PLAIN`, `TLS SASL/DIGEST-MD5` and `TLS SASL/CRAM-MD5`. |
179-
| `otel.jmx.realm` | no | The realm is required by profile SASL/DIGEST-MD5. |

contrib/jmx-metrics/jmx-metrics.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sourceSets.test.java.srcDirs = []
2626
mainClassName = 'io.opentelemetry.contrib.jmxmetrics.JmxMetrics'
2727

2828
def versions = [
29-
grpc : '1.30.2',
29+
grpc : '1.37.0',
3030
protobuf : '3.11.4',
3131
groovy : '2.5.11',
3232
slf4j : "1.7.30",
@@ -45,10 +45,13 @@ dependencies {
4545
"io.prometheus:simpleclient:${versions.prometheus}",
4646
"io.prometheus:simpleclient_httpserver:${versions.prometheus}",
4747
libraries.otelApi,
48+
libraries.otelApiMetrics,
49+
libraries.otelAutoconfig,
4850
libraries.otelExporterLogging,
4951
libraries.otelExporterOtlp,
5052
libraries.otelExporterPrometheus,
5153
libraries.otelSdk,
54+
libraries.otelSdkMetrics,
5255
libraries.otelSdkTesting,
5356
deps.slf4j,
5457
dependencies.create(group: 'org.slf4j', name: 'slf4j-simple', version: versions.slf4j)

0 commit comments

Comments
 (0)