Skip to content

Commit 6704450

Browse files
Adopt async instruments in JVM target script (#22)
1 parent 66f487e commit 6704450

File tree

3 files changed

+73
-41
lines changed

3 files changed

+73
-41
lines changed

contrib/jmx-metrics/docs/target-systems/jvm.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,79 @@ These metrics are sourced from Cassandra's exposed Dropwizard Metrics for each n
1010
* Name: `jvm.classes.loaded`
1111
* Description: The number of loaded classes
1212
* Unit: `1`
13-
* Instrument Type: LongUpDownCounter
13+
* Instrument Type: LongValueObserver
1414

1515
* Name: `jvm.gc.collections.count`
1616
* Description: The total number of garbage collections that have occurred
1717
* Unit: `1`
18-
* Instrument Type: LongCounter
18+
* Instrument Type: LongSumObserver
1919

2020
* Name: `jvm.gc.collections.elapsed`
2121
* Description: The approximate accumulated collection elapsed time
2222
* Unit: `ms`
23-
* Instrument Type: LongCounter
23+
* Instrument Type: LongSumObserver
2424

2525
* Name: `jvm.memory.heap.init`
2626
* Description: The initial amount of memory that the JVM requests from the operating system for the heap
2727
* Unit: `by`
28-
* Instrument Type: LongUpDownCounter
28+
* Instrument Type: LongValueObserver
2929

3030
* Name: `jvm.memory.heap.max`
3131
* Description: The maximum amount of memory can be used for the heap
3232
* Unit: `by`
33-
* Instrument Type: LongUpDownCounter
33+
* Instrument Type: LongValueObserver
3434

3535
* Name: `jvm.memory.heap.used`
3636
* Description: The current heap memory usage
3737
* Unit: `by`
38-
* Instrument Type: LongUpDownCounter
38+
* Instrument Type: LongValueObserver
3939

4040
* Name: `jvm.memory.heap.committed`
4141
* Description: The amount of memory that is guaranteed to be available for the heap
4242
* Unit: `by`
43-
* Instrument Type: LongUpDownCounter
43+
* Instrument Type: LongValueObserver
4444

4545
* Name: `jvm.memory.nonheap.init`
4646
* Description: The initial amount of memory that the JVM requests from the operating system for non-heap purposes
4747
* Unit: `by`
48-
* Instrument Type: LongUpDownCounter
48+
* Instrument Type: LongValueObserver
4949

5050
* Name: `jvm.memory.nonheap.max`
5151
* Description: The maximum amount of memory can be used for non-heap purposes
5252
* Unit: `by`
53-
* Instrument Type: LongUpDownCounter
53+
* Instrument Type: LongValueObserver
5454

5555
* Name: `jvm.memory.nonheap.used`
5656
* Description: The current non-heap memory usage
5757
* Unit: `by`
58-
* Instrument Type: LongUpDownCounter
58+
* Instrument Type: LongValueObserver
5959

6060
* Name: `jvm.memory.nonheap.committed`
6161
* Description: The amount of memory that is guaranteed to be available for non-heap purposes
6262
* Unit: `by`
63-
* Instrument Type: LongUpDownCounter
63+
* Instrument Type: LongValueObserver
6464

6565
* Name: `jvm.memory.pool.init`
6666
* Description: The initial amount of memory that the JVM requests from the operating system for the memory pool
6767
* Unit: `by`
68-
* Instrument Type: LongUpDownCounter
68+
* Instrument Type: LongValueObserver
6969

7070
* Name: `jvm.memory.pool.max`
7171
* Description: The maximum amount of memory can be used for the memory pool
7272
* Unit: `by`
73-
* Instrument Type: LongUpDownCounter
73+
* Instrument Type: LongValueObserver
7474

7575
* Name: `jvm.memory.pool.used`
7676
* Description: The current memory pool memory usage
7777
* Unit: `by`
78-
* Instrument Type: LongUpDownCounter
78+
* Instrument Type: LongValueObserver
7979

8080
* Name: `jvm.memory.pool.committed`
8181
* Description: The amount of memory that is guaranteed to be available for the memory pool
8282
* Unit: `by`
83-
* Instrument Type: LongUpDownCounter
83+
* Instrument Type: LongValueObserver
8484

8585
* Name: `jvm.threads.count`
8686
* Description: The current number of threads
8787
* Unit: `1`
88-
* Instrument Type: LongUpDownCounter
88+
* Instrument Type: LongValueObserver

contrib/jmx-metrics/src/main/resources/target-systems/jvm.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@
1616

1717
def classLoading = otel.mbean("java.lang:type=ClassLoading")
1818
otel.instrument(classLoading, "jvm.classes.loaded", "number of loaded classes",
19-
"1", "LoadedClassCount", otel.&longUpDownCounter)
19+
"1", "LoadedClassCount", otel.&longValueObserver)
2020

2121
def garbageCollector = otel.mbeans("java.lang:type=GarbageCollector,*")
2222
otel.instrument(garbageCollector, "jvm.gc.collections.count", "total number of collections that have occurred",
2323
"1", ["name" : { mbean -> mbean.name().getKeyProperty("name") }],
24-
"CollectionCount", otel.&longCounter)
24+
"CollectionCount", otel.&longSumObserver)
2525
otel.instrument(garbageCollector, "jvm.gc.collections.elapsed",
2626
"the approximate accumulated collection elapsed time in milliseconds", "ms",
2727
["name" : { mbean -> mbean.name().getKeyProperty("name") }],
28-
"CollectionTime", otel.&longCounter)
28+
"CollectionTime", otel.&longSumObserver)
2929

3030
def memory = otel.mbean("java.lang:type=Memory")
3131
otel.instrument(memory, "jvm.memory.heap", "current heap usage",
32-
"by", "HeapMemoryUsage", otel.&longUpDownCounter)
32+
"by", "HeapMemoryUsage", otel.&longValueObserver)
3333
otel.instrument(memory, "jvm.memory.nonheap", "current non-heap usage",
34-
"by", "NonHeapMemoryUsage", otel.&longUpDownCounter)
34+
"by", "NonHeapMemoryUsage", otel.&longValueObserver)
3535

3636
def memoryPool = otel.mbeans("java.lang:type=MemoryPool,*")
3737
otel.instrument(memoryPool, "jvm.memory.pool", "current memory pool usage",
3838
"by", ["name" : { mbean -> mbean.name().getKeyProperty("name") }],
39-
"Usage", otel.&longUpDownCounter)
39+
"Usage", otel.&longValueObserver)
4040

4141
def threading = otel.mbean("java.lang:type=Threading")
4242
otel.instrument(threading, "jvm.threads.count", "number of threads",
43-
"1", "ThreadCount", otel.&longUpDownCounter)
43+
"1", "ThreadCount", otel.&longValueObserver)

contrib/jmx-metrics/src/test/groovy/io/opentelemetry/contrib/jmxmetrics/target-systems/JVMTargetSystemIntegrationTests.groovy

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.opentelemetry.contrib.jmxmetrics
1818

19+
import io.opentelemetry.proto.metrics.v1.IntGauge
1920
import io.opentelemetry.proto.metrics.v1.IntSum
2021

2122
import io.opentelemetry.proto.common.v1.InstrumentationLibrary
@@ -70,71 +71,84 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
7071
'jvm.classes.loaded',
7172
'number of loaded classes',
7273
'1',
73-
[]
74+
[],
75+
IntGauge
7476
],
7577
[
7678
'jvm.gc.collections.count',
7779
'total number of collections that have occurred',
7880
'1',
7981
[
8082
"ConcurrentMarkSweep",
81-
"ParNew"]
83+
"ParNew"
84+
],
85+
IntSum
8286
],
8387
[
8488
'jvm.gc.collections.elapsed',
8589
'the approximate accumulated collection elapsed time in milliseconds',
8690
'ms',
8791
[
8892
"ConcurrentMarkSweep",
89-
"ParNew"]
93+
"ParNew"
94+
],
95+
IntSum
9096
],
9197
[
9298
'jvm.memory.heap.committed',
9399
'current heap usage',
94100
'by',
95-
[]
101+
[],
102+
IntGauge
96103
],
97104
[
98105
'jvm.memory.heap.init',
99106
'current heap usage',
100107
'by',
101-
[]
108+
[],
109+
IntGauge
102110
],
103111
[
104112
'jvm.memory.heap.max',
105113
'current heap usage',
106114
'by',
107-
[]
115+
[],
116+
IntGauge
108117
],
109118
[
110119
'jvm.memory.heap.used',
111120
'current heap usage',
112121
'by',
113-
[]
122+
[],
123+
IntGauge
114124
],
115125
[
116126
'jvm.memory.nonheap.committed',
117127
'current non-heap usage',
118128
'by',
119-
[]
129+
[],
130+
IntGauge
120131
],
121132
[
122133
'jvm.memory.nonheap.init',
123134
'current non-heap usage',
124135
'by',
125-
[]
136+
[],
137+
IntGauge
126138
],
127139
[
128140
'jvm.memory.nonheap.max',
129141
'current non-heap usage',
130142
'by',
131-
[]
143+
[],
144+
IntGauge
132145
],
133146
[
134147
'jvm.memory.nonheap.used',
135148
'current non-heap usage',
136149
'by',
137-
[]
150+
[],
151+
IntGauge
138152
],
139153
[
140154
'jvm.memory.pool.committed',
@@ -146,7 +160,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
146160
"CMS Old Gen",
147161
"Compressed Class Space",
148162
"Metaspace",
149-
"Par Survivor Space"]
163+
"Par Survivor Space"
164+
],
165+
IntGauge
150166
],
151167
[
152168
'jvm.memory.pool.init',
@@ -158,7 +174,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
158174
"CMS Old Gen",
159175
"Compressed Class Space",
160176
"Metaspace",
161-
"Par Survivor Space"]
177+
"Par Survivor Space"
178+
],
179+
IntGauge
162180
],
163181
[
164182
'jvm.memory.pool.max',
@@ -170,7 +188,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
170188
"CMS Old Gen",
171189
"Compressed Class Space",
172190
"Metaspace",
173-
"Par Survivor Space"]
191+
"Par Survivor Space"
192+
],
193+
IntGauge
174194
],
175195
[
176196
'jvm.memory.pool.used',
@@ -182,21 +202,33 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
182202
"CMS Old Gen",
183203
"Compressed Class Space",
184204
"Metaspace",
185-
"Par Survivor Space"]
205+
"Par Survivor Space"
206+
],
207+
IntGauge
186208
],
187209
[
188210
'jvm.threads.count',
189211
'number of threads',
190212
'1',
191-
[]
213+
[],
214+
IntGauge
192215
],
193216
].eachWithIndex{ item, index ->
217+
def expectedType = item[4]
218+
194219
Metric metric = metrics.get(index)
195220
assert metric.name == item[0]
196221
assert metric.description == item[1]
197222
assert metric.unit == item[2]
198-
assert metric.hasIntSum()
199-
IntSum datapoints = metric.intSum
223+
224+
def datapoints
225+
if (expectedType == IntGauge) {
226+
assert metric.hasIntGauge()
227+
datapoints = metric.intGauge
228+
} else {
229+
assert metric.hasIntSum()
230+
datapoints = metric.intSum
231+
}
200232
def expectedLabelCount = item[3].size()
201233
def expectedLabels = item[3] as Set
202234

0 commit comments

Comments
 (0)