Skip to content

Commit

Permalink
Adding jvmVersion dimension in JVM Monitor (#16262)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavbhole authored Apr 11, 2024
1 parent 9f358f5 commit fc2600b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
26 changes: 13 additions & 13 deletions docs/operations/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,19 +399,19 @@ For more information, see [Enabling Metrics](../configuration/index.md#enabling-

|Metric|Description|Dimensions|Normal value|
|------|-----------|----------|------------|
|`jvm/pool/committed`|Committed pool|`poolKind`, `poolName`|Close to max pool|
|`jvm/pool/init`|Initial pool|`poolKind`, `poolName`|Varies|
|`jvm/pool/max`|Max pool|`poolKind`, `poolName`|Varies|
|`jvm/pool/used`|Pool used|`poolKind`, `poolName`|< max pool|
|`jvm/bufferpool/count`|Bufferpool count|`bufferpoolName`|Varies|
|`jvm/bufferpool/used`|Bufferpool used|`bufferpoolName`|Close to capacity|
|`jvm/bufferpool/capacity`|Bufferpool capacity|`bufferpoolName`|Varies|
|`jvm/mem/init`|Initial memory|`memKind`|Varies|
|`jvm/mem/max`|Max memory|`memKind`|Varies|
|`jvm/mem/used`|Used memory|`memKind`|< max memory|
|`jvm/mem/committed`|Committed memory|`memKind`|Close to max memory|
|`jvm/gc/count`|Garbage collection count|`gcName` (cms/g1/parallel/etc.), `gcGen` (old/young)|Varies|
|`jvm/gc/cpu`|Count of CPU time in Nanoseconds spent on garbage collection. Note: `jvm/gc/cpu` represents the total time over multiple GC cycles; divide by `jvm/gc/count` to get the mean GC time per cycle.|`gcName`, `gcGen`|Sum of `jvm/gc/cpu` should be within 10-30% of sum of `jvm/cpu/total`, depending on the GC algorithm used (reported by [`JvmCpuMonitor`](../configuration/index.md#enabling-metrics)). |
|`jvm/pool/committed`|Committed pool|`poolKind`, `poolName`, `jvmVersion`|Close to max pool|
|`jvm/pool/init`|Initial pool|`poolKind`, `poolName`, `jvmVersion`|Varies|
|`jvm/pool/max`|Max pool|`poolKind`, `poolName`, `jvmVersion`|Varies|
|`jvm/pool/used`|Pool used|`poolKind`, `poolName`, `jvmVersion`|< max pool|
|`jvm/bufferpool/count`|Bufferpool count|`bufferpoolName`, `jvmVersion`|Varies|
|`jvm/bufferpool/used`|Bufferpool used|`bufferpoolName`, `jvmVersion`|Close to capacity|
|`jvm/bufferpool/capacity`|Bufferpool capacity|`bufferpoolName`, `jvmVersion`|Varies|
|`jvm/mem/init`|Initial memory|`memKind`, `jvmVersion`|Varies|
|`jvm/mem/max`|Max memory|`memKind`, `jvmVersion`|Varies|
|`jvm/mem/used`|Used memory|`memKind`, `jvmVersion`|< max memory|
|`jvm/mem/committed`|Committed memory|`memKind`, `jvmVersion`|Close to max memory|
|`jvm/gc/count`|Garbage collection count|`gcName` (cms/g1/parallel/etc.), `gcGen` (old/young), `jvmVersion`|Varies|
|`jvm/gc/cpu`|Count of CPU time in Nanoseconds spent on garbage collection. Note: `jvm/gc/cpu` represents the total time over multiple GC cycles; divide by `jvm/gc/count` to get the mean GC time per cycle.|`gcName`, `gcGen`, `jvmVersion`|Sum of `jvm/gc/cpu` should be within 10-30% of sum of `jvm/cpu/total`, depending on the GC algorithm used (reported by [`JvmCpuMonitor`](../configuration/index.md#enabling-metrics)). |

### ZooKeeper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
public class JvmMonitor extends FeedDefiningMonitor
{

private final Map<String, String[]> dimensions;

private static final String JVM_VERSION = "jvmVersion";
private static final String JAVA_VERSION = System.getProperty("java.version");
@VisibleForTesting
@Nullable
final GcCollectors gcCollectors;

private final Map<String, String[]> dimensions;
@Nullable
private final AllocationMetricCollector collector;

Expand Down Expand Up @@ -83,6 +83,7 @@ private void emitThreadAllocationMetrics(ServiceEmitter emitter)
{
final ServiceMetricEvent.Builder builder = builder();
MonitorUtils.addDimensionsToBuilder(builder, dimensions);
builder.setDimension(JVM_VERSION, JAVA_VERSION);
if (collector != null) {
long delta = collector.calculateDelta();
emitter.emit(builder.setMetric("jvm/heapAlloc/bytes", delta));
Expand All @@ -104,7 +105,9 @@ private void emitJvmMemMetrics(ServiceEmitter emitter)
for (Map.Entry<String, MemoryUsage> entry : usages.entrySet()) {
final String kind = entry.getKey();
final MemoryUsage usage = entry.getValue();
final ServiceMetricEvent.Builder builder = builder().setDimension("memKind", kind);
final ServiceMetricEvent.Builder builder = builder()
.setDimension("memKind", kind)
.setDimension(JVM_VERSION, JAVA_VERSION);
MonitorUtils.addDimensionsToBuilder(builder, dimensions);

emitter.emit(builder.setMetric("jvm/mem/max", usage.getMax()));
Expand All @@ -119,7 +122,8 @@ private void emitJvmMemMetrics(ServiceEmitter emitter)
final MemoryUsage usage = pool.getUsage();
final ServiceMetricEvent.Builder builder = builder()
.setDimension("poolKind", kind)
.setDimension("poolName", pool.getName());
.setDimension("poolName", pool.getName())
.setDimension(JVM_VERSION, JAVA_VERSION);
MonitorUtils.addDimensionsToBuilder(builder, dimensions);

emitter.emit(builder.setMetric("jvm/pool/max", usage.getMax()));
Expand All @@ -132,7 +136,9 @@ private void emitJvmMemMetrics(ServiceEmitter emitter)
private void emitDirectMemMetrics(ServiceEmitter emitter)
{
for (BufferPoolMXBean pool : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
final ServiceMetricEvent.Builder builder = builder().setDimension("bufferpoolName", pool.getName());
final ServiceMetricEvent.Builder builder = builder()
.setDimension("bufferpoolName", pool.getName())
.setDimension(JVM_VERSION, JAVA_VERSION);
MonitorUtils.addDimensionsToBuilder(builder, dimensions);

emitter.emit(builder.setMetric("jvm/bufferpool/capacity", pool.getTotalCapacity()));
Expand Down Expand Up @@ -182,23 +188,20 @@ void emit(ServiceEmitter emitter, Map<String, String[]> dimensions)

private class GcGenerationCollector
{
private final String generation;
private final String collectorName;
private final GarbageCollectorMXBean gcBean;

private long lastInvocations = 0;
private long lastCpuMillis = 0;

private static final String GC_YOUNG_GENERATION_NAME = "young";
private static final String GC_OLD_GENERATION_NAME = "old";
private static final String GC_ZGC_GENERATION_NAME = "zgc";

private static final String CMS_COLLECTOR_NAME = "cms";
private static final String G1_COLLECTOR_NAME = "g1";
private static final String PARALLEL_COLLECTOR_NAME = "parallel";
private static final String SERIAL_COLLECTOR_NAME = "serial";
private static final String ZGC_COLLECTOR_NAME = "zgc";
private static final String SHENANDOAN_COLLECTOR_NAME = "shenandoah";
private final String generation;
private final String collectorName;
private final GarbageCollectorMXBean gcBean;
private long lastInvocations = 0;
private long lastCpuMillis = 0;

GcGenerationCollector(GarbageCollectorMXBean gcBean)
{
Expand Down Expand Up @@ -253,16 +256,17 @@ private Pair<String, String> getReadableName(String name)
void emit(ServiceEmitter emitter, Map<String, String[]> dimensions)
{
ImmutableMap.Builder<String, String[]> dimensionsCopyBuilder = ImmutableMap
.<String, String[]>builder()
.putAll(dimensions)
.put("gcGen", new String[]{generation});
.<String, String[]>builder()
.putAll(dimensions)
.put("gcGen", new String[]{generation});

dimensionsCopyBuilder.put("gcName", new String[]{collectorName});

Map<String, String[]> dimensionsCopy = dimensionsCopyBuilder.build();

final ServiceMetricEvent.Builder builder = builder();
MonitorUtils.addDimensionsToBuilder(builder, dimensionsCopy);
builder.setDimension(JVM_VERSION, JAVA_VERSION);

long newInvocations = gcBean.getCollectionCount();
emitter.emit(builder.setMetric("jvm/gc/count", newInvocations - lastInvocations));
Expand Down Expand Up @@ -309,7 +313,9 @@ void emit(ServiceEmitter emitter, Map<String, String[]> dimensions)
final ServiceMetricEvent.Builder builder = builder();
MonitorUtils.addDimensionsToBuilder(builder, dimensions);

builder.setDimension("gcGenSpaceName", name);
builder
.setDimension(JVM_VERSION, JAVA_VERSION)
.setDimension("gcGenSpaceName", name);

emitter.emit(builder.setMetric("jvm/gc/mem/max", memoryUsage.getMax()));
emitter.emit(builder.setMetric("jvm/gc/mem/capacity", memoryUsage.getCommitted()));
Expand Down
1 change: 1 addition & 0 deletions website/.spelling
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,7 @@ EventReceiverFirehose
EventReceiverFirehoseMonitor
Filesystem
JVMMonitor
jvmVersion
QueryCountStatsMonitor
RealtimeMetricsMonitor
Sys
Expand Down

0 comments on commit fc2600b

Please sign in to comment.