Adopt async instruments in JVM target script (#22)

This commit is contained in:
Ryan Fitzpatrick 2020-11-12 11:56:31 -05:00 committed by GitHub
parent 66f487eb1e
commit 67044507cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 41 deletions

View File

@ -10,79 +10,79 @@ These metrics are sourced from Cassandra's exposed Dropwizard Metrics for each n
* Name: `jvm.classes.loaded` * Name: `jvm.classes.loaded`
* Description: The number of loaded classes * Description: The number of loaded classes
* Unit: `1` * Unit: `1`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.gc.collections.count` * Name: `jvm.gc.collections.count`
* Description: The total number of garbage collections that have occurred * Description: The total number of garbage collections that have occurred
* Unit: `1` * Unit: `1`
* Instrument Type: LongCounter * Instrument Type: LongSumObserver
* Name: `jvm.gc.collections.elapsed` * Name: `jvm.gc.collections.elapsed`
* Description: The approximate accumulated collection elapsed time * Description: The approximate accumulated collection elapsed time
* Unit: `ms` * Unit: `ms`
* Instrument Type: LongCounter * Instrument Type: LongSumObserver
* Name: `jvm.memory.heap.init` * Name: `jvm.memory.heap.init`
* Description: The initial amount of memory that the JVM requests from the operating system for the heap * Description: The initial amount of memory that the JVM requests from the operating system for the heap
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.heap.max` * Name: `jvm.memory.heap.max`
* Description: The maximum amount of memory can be used for the heap * Description: The maximum amount of memory can be used for the heap
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.heap.used` * Name: `jvm.memory.heap.used`
* Description: The current heap memory usage * Description: The current heap memory usage
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.heap.committed` * Name: `jvm.memory.heap.committed`
* Description: The amount of memory that is guaranteed to be available for the heap * Description: The amount of memory that is guaranteed to be available for the heap
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.nonheap.init` * Name: `jvm.memory.nonheap.init`
* Description: The initial amount of memory that the JVM requests from the operating system for non-heap purposes * Description: The initial amount of memory that the JVM requests from the operating system for non-heap purposes
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.nonheap.max` * Name: `jvm.memory.nonheap.max`
* Description: The maximum amount of memory can be used for non-heap purposes * Description: The maximum amount of memory can be used for non-heap purposes
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.nonheap.used` * Name: `jvm.memory.nonheap.used`
* Description: The current non-heap memory usage * Description: The current non-heap memory usage
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.nonheap.committed` * Name: `jvm.memory.nonheap.committed`
* Description: The amount of memory that is guaranteed to be available for non-heap purposes * Description: The amount of memory that is guaranteed to be available for non-heap purposes
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.pool.init` * Name: `jvm.memory.pool.init`
* Description: The initial amount of memory that the JVM requests from the operating system for the memory pool * Description: The initial amount of memory that the JVM requests from the operating system for the memory pool
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.pool.max` * Name: `jvm.memory.pool.max`
* Description: The maximum amount of memory can be used for the memory pool * Description: The maximum amount of memory can be used for the memory pool
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.pool.used` * Name: `jvm.memory.pool.used`
* Description: The current memory pool memory usage * Description: The current memory pool memory usage
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.memory.pool.committed` * Name: `jvm.memory.pool.committed`
* Description: The amount of memory that is guaranteed to be available for the memory pool * Description: The amount of memory that is guaranteed to be available for the memory pool
* Unit: `by` * Unit: `by`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver
* Name: `jvm.threads.count` * Name: `jvm.threads.count`
* Description: The current number of threads * Description: The current number of threads
* Unit: `1` * Unit: `1`
* Instrument Type: LongUpDownCounter * Instrument Type: LongValueObserver

View File

@ -16,28 +16,28 @@
def classLoading = otel.mbean("java.lang:type=ClassLoading") def classLoading = otel.mbean("java.lang:type=ClassLoading")
otel.instrument(classLoading, "jvm.classes.loaded", "number of loaded classes", otel.instrument(classLoading, "jvm.classes.loaded", "number of loaded classes",
"1", "LoadedClassCount", otel.&longUpDownCounter) "1", "LoadedClassCount", otel.&longValueObserver)
def garbageCollector = otel.mbeans("java.lang:type=GarbageCollector,*") def garbageCollector = otel.mbeans("java.lang:type=GarbageCollector,*")
otel.instrument(garbageCollector, "jvm.gc.collections.count", "total number of collections that have occurred", otel.instrument(garbageCollector, "jvm.gc.collections.count", "total number of collections that have occurred",
"1", ["name" : { mbean -> mbean.name().getKeyProperty("name") }], "1", ["name" : { mbean -> mbean.name().getKeyProperty("name") }],
"CollectionCount", otel.&longCounter) "CollectionCount", otel.&longSumObserver)
otel.instrument(garbageCollector, "jvm.gc.collections.elapsed", otel.instrument(garbageCollector, "jvm.gc.collections.elapsed",
"the approximate accumulated collection elapsed time in milliseconds", "ms", "the approximate accumulated collection elapsed time in milliseconds", "ms",
["name" : { mbean -> mbean.name().getKeyProperty("name") }], ["name" : { mbean -> mbean.name().getKeyProperty("name") }],
"CollectionTime", otel.&longCounter) "CollectionTime", otel.&longSumObserver)
def memory = otel.mbean("java.lang:type=Memory") def memory = otel.mbean("java.lang:type=Memory")
otel.instrument(memory, "jvm.memory.heap", "current heap usage", otel.instrument(memory, "jvm.memory.heap", "current heap usage",
"by", "HeapMemoryUsage", otel.&longUpDownCounter) "by", "HeapMemoryUsage", otel.&longValueObserver)
otel.instrument(memory, "jvm.memory.nonheap", "current non-heap usage", otel.instrument(memory, "jvm.memory.nonheap", "current non-heap usage",
"by", "NonHeapMemoryUsage", otel.&longUpDownCounter) "by", "NonHeapMemoryUsage", otel.&longValueObserver)
def memoryPool = otel.mbeans("java.lang:type=MemoryPool,*") def memoryPool = otel.mbeans("java.lang:type=MemoryPool,*")
otel.instrument(memoryPool, "jvm.memory.pool", "current memory pool usage", otel.instrument(memoryPool, "jvm.memory.pool", "current memory pool usage",
"by", ["name" : { mbean -> mbean.name().getKeyProperty("name") }], "by", ["name" : { mbean -> mbean.name().getKeyProperty("name") }],
"Usage", otel.&longUpDownCounter) "Usage", otel.&longValueObserver)
def threading = otel.mbean("java.lang:type=Threading") def threading = otel.mbean("java.lang:type=Threading")
otel.instrument(threading, "jvm.threads.count", "number of threads", otel.instrument(threading, "jvm.threads.count", "number of threads",
"1", "ThreadCount", otel.&longUpDownCounter) "1", "ThreadCount", otel.&longValueObserver)

View File

@ -16,6 +16,7 @@
package io.opentelemetry.contrib.jmxmetrics package io.opentelemetry.contrib.jmxmetrics
import io.opentelemetry.proto.metrics.v1.IntGauge
import io.opentelemetry.proto.metrics.v1.IntSum import io.opentelemetry.proto.metrics.v1.IntSum
import io.opentelemetry.proto.common.v1.InstrumentationLibrary import io.opentelemetry.proto.common.v1.InstrumentationLibrary
@ -70,7 +71,8 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
'jvm.classes.loaded', 'jvm.classes.loaded',
'number of loaded classes', 'number of loaded classes',
'1', '1',
[] [],
IntGauge
], ],
[ [
'jvm.gc.collections.count', 'jvm.gc.collections.count',
@ -78,7 +80,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
'1', '1',
[ [
"ConcurrentMarkSweep", "ConcurrentMarkSweep",
"ParNew"] "ParNew"
],
IntSum
], ],
[ [
'jvm.gc.collections.elapsed', 'jvm.gc.collections.elapsed',
@ -86,55 +90,65 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
'ms', 'ms',
[ [
"ConcurrentMarkSweep", "ConcurrentMarkSweep",
"ParNew"] "ParNew"
],
IntSum
], ],
[ [
'jvm.memory.heap.committed', 'jvm.memory.heap.committed',
'current heap usage', 'current heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.heap.init', 'jvm.memory.heap.init',
'current heap usage', 'current heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.heap.max', 'jvm.memory.heap.max',
'current heap usage', 'current heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.heap.used', 'jvm.memory.heap.used',
'current heap usage', 'current heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.nonheap.committed', 'jvm.memory.nonheap.committed',
'current non-heap usage', 'current non-heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.nonheap.init', 'jvm.memory.nonheap.init',
'current non-heap usage', 'current non-heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.nonheap.max', 'jvm.memory.nonheap.max',
'current non-heap usage', 'current non-heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.nonheap.used', 'jvm.memory.nonheap.used',
'current non-heap usage', 'current non-heap usage',
'by', 'by',
[] [],
IntGauge
], ],
[ [
'jvm.memory.pool.committed', 'jvm.memory.pool.committed',
@ -146,7 +160,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
"CMS Old Gen", "CMS Old Gen",
"Compressed Class Space", "Compressed Class Space",
"Metaspace", "Metaspace",
"Par Survivor Space"] "Par Survivor Space"
],
IntGauge
], ],
[ [
'jvm.memory.pool.init', 'jvm.memory.pool.init',
@ -158,7 +174,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
"CMS Old Gen", "CMS Old Gen",
"Compressed Class Space", "Compressed Class Space",
"Metaspace", "Metaspace",
"Par Survivor Space"] "Par Survivor Space"
],
IntGauge
], ],
[ [
'jvm.memory.pool.max', 'jvm.memory.pool.max',
@ -170,7 +188,9 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
"CMS Old Gen", "CMS Old Gen",
"Compressed Class Space", "Compressed Class Space",
"Metaspace", "Metaspace",
"Par Survivor Space"] "Par Survivor Space"
],
IntGauge
], ],
[ [
'jvm.memory.pool.used', 'jvm.memory.pool.used',
@ -182,21 +202,33 @@ class JVMTargetSystemIntegrationTests extends OtlpIntegrationTest {
"CMS Old Gen", "CMS Old Gen",
"Compressed Class Space", "Compressed Class Space",
"Metaspace", "Metaspace",
"Par Survivor Space"] "Par Survivor Space"
],
IntGauge
], ],
[ [
'jvm.threads.count', 'jvm.threads.count',
'number of threads', 'number of threads',
'1', '1',
[] [],
IntGauge
], ],
].eachWithIndex{ item, index -> ].eachWithIndex{ item, index ->
def expectedType = item[4]
Metric metric = metrics.get(index) Metric metric = metrics.get(index)
assert metric.name == item[0] assert metric.name == item[0]
assert metric.description == item[1] assert metric.description == item[1]
assert metric.unit == item[2] assert metric.unit == item[2]
def datapoints
if (expectedType == IntGauge) {
assert metric.hasIntGauge()
datapoints = metric.intGauge
} else {
assert metric.hasIntSum() assert metric.hasIntSum()
IntSum datapoints = metric.intSum datapoints = metric.intSum
}
def expectedLabelCount = item[3].size() def expectedLabelCount = item[3].size()
def expectedLabels = item[3] as Set def expectedLabels = item[3] as Set