Fix units for some metrics (#140)

* Fix units for some metrics

* These are actually bytes and formatted based on size
This commit is contained in:
Ben Evans 2021-12-01 02:10:51 +01:00 committed by GitHub
parent 92998b6791
commit 08ecf8321b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 13 deletions

View File

@ -11,7 +11,8 @@ public final class Constants {
private Constants() {} private Constants() {}
public static final String ONE = "1"; public static final String ONE = "1";
public static final String KILOBYTES = "kb"; public static final String HERTZ = "Hz";
public static final String BYTES = "B";
public static final String MILLISECONDS = "ms"; public static final String MILLISECONDS = "ms";
public static final String PERCENTAGE = "%age"; public static final String PERCENTAGE = "%age";
public static final String READ = "read"; public static final String READ = "read";

View File

@ -5,7 +5,7 @@
package io.opentelemetry.contrib.jfr.metrics.internal.cpu; package io.opentelemetry.contrib.jfr.metrics.internal.cpu;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ONE; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.HERTZ;
import io.opentelemetry.api.metrics.*; import io.opentelemetry.api.metrics.*;
import io.opentelemetry.contrib.jfr.metrics.internal.RecordedEventHandler; import io.opentelemetry.contrib.jfr.metrics.internal.RecordedEventHandler;
@ -28,7 +28,7 @@ public final class ContextSwitchRateHandler implements RecordedEventHandler {
otelMeter otelMeter
.upDownCounterBuilder(METRIC_NAME) .upDownCounterBuilder(METRIC_NAME)
.ofDoubles() .ofDoubles()
.setUnit(ONE) .setUnit(HERTZ)
.buildWithCallback(codm -> codm.observe(value)); .buildWithCallback(codm -> codm.observe(value));
return this; return this;
} }

View File

@ -8,6 +8,7 @@ package io.opentelemetry.contrib.jfr.metrics.internal.cpu;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_CPU_USAGE; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_CPU_USAGE;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.MACHINE; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.MACHINE;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ONE; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ONE;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.PERCENTAGE;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.SYSTEM; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.SYSTEM;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.USER; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.USER;
@ -43,7 +44,7 @@ public final class OverallCPULoadHandler implements RecordedEventHandler {
var attr = Attributes.of(ATTR_CPU_USAGE, USER); var attr = Attributes.of(ATTR_CPU_USAGE, USER);
var builder = otelMeter.histogramBuilder(METRIC_NAME); var builder = otelMeter.histogramBuilder(METRIC_NAME);
builder.setDescription(DESCRIPTION); builder.setDescription(DESCRIPTION);
builder.setUnit(ONE); builder.setUnit(PERCENTAGE);
userHistogram = builder.build().bind(attr); userHistogram = builder.build().bind(attr);
attr = Attributes.of(ATTR_CPU_USAGE, SYSTEM); attr = Attributes.of(ATTR_CPU_USAGE, SYSTEM);

View File

@ -6,8 +6,8 @@
package io.opentelemetry.contrib.jfr.metrics.internal.memory; package io.opentelemetry.contrib.jfr.metrics.internal.memory;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_MEMORY_USAGE; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_MEMORY_USAGE;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.BYTES;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.COMMITTED; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.COMMITTED;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.KILOBYTES;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.USED; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.USED;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
@ -57,13 +57,13 @@ public final class GCHeapSummaryHandler implements RecordedEventHandler {
var attr = Attributes.of(ATTR_MEMORY_USAGE, USED); var attr = Attributes.of(ATTR_MEMORY_USAGE, USED);
builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY); builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY);
builder.setDescription(DESCRIPTION); builder.setDescription(DESCRIPTION);
builder.setUnit(KILOBYTES); builder.setUnit(BYTES);
usedHistogram = builder.build().bind(attr); usedHistogram = builder.build().bind(attr);
attr = Attributes.of(ATTR_MEMORY_USAGE, COMMITTED); attr = Attributes.of(ATTR_MEMORY_USAGE, COMMITTED);
builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY); builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY);
builder.setDescription(DESCRIPTION); builder.setDescription(DESCRIPTION);
builder.setUnit(KILOBYTES); builder.setUnit(BYTES);
committedHistogram = builder.build().bind(attr); committedHistogram = builder.build().bind(attr);
return this; return this;

View File

@ -7,12 +7,12 @@ package io.opentelemetry.contrib.jfr.metrics.internal.memory;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_ARENA_NAME; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_ARENA_NAME;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_THREAD_NAME; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_THREAD_NAME;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.BYTES;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.METRIC_NAME_MEMORY_ALLOCATION; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.METRIC_NAME_MEMORY_ALLOCATION;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.BoundDoubleHistogram; import io.opentelemetry.api.metrics.BoundDoubleHistogram;
import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.contrib.jfr.metrics.internal.Constants;
import io.opentelemetry.contrib.jfr.metrics.internal.RecordedEventHandler; import io.opentelemetry.contrib.jfr.metrics.internal.RecordedEventHandler;
import jdk.jfr.consumer.RecordedEvent; import jdk.jfr.consumer.RecordedEvent;
@ -35,7 +35,7 @@ public final class PerThreadObjectAllocationInNewTLABHandler implements Recorded
var attr = Attributes.of(ATTR_THREAD_NAME, threadName, ATTR_ARENA_NAME, TLAB); var attr = Attributes.of(ATTR_THREAD_NAME, threadName, ATTR_ARENA_NAME, TLAB);
var builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY_ALLOCATION); var builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY_ALLOCATION);
builder.setDescription(DESCRIPTION); builder.setDescription(DESCRIPTION);
builder.setUnit(Constants.KILOBYTES); builder.setUnit(BYTES);
histogram = builder.build().bind(attr); histogram = builder.build().bind(attr);
return this; return this;
} }

View File

@ -7,12 +7,12 @@ package io.opentelemetry.contrib.jfr.metrics.internal.memory;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_ARENA_NAME; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_ARENA_NAME;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_THREAD_NAME; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_THREAD_NAME;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.BYTES;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.METRIC_NAME_MEMORY_ALLOCATION; import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.METRIC_NAME_MEMORY_ALLOCATION;
import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.BoundDoubleHistogram; import io.opentelemetry.api.metrics.BoundDoubleHistogram;
import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.contrib.jfr.metrics.internal.Constants;
import io.opentelemetry.contrib.jfr.metrics.internal.RecordedEventHandler; import io.opentelemetry.contrib.jfr.metrics.internal.RecordedEventHandler;
import jdk.jfr.consumer.RecordedEvent; import jdk.jfr.consumer.RecordedEvent;
@ -35,7 +35,7 @@ public final class PerThreadObjectAllocationOutsideTLABHandler implements Record
var attr = Attributes.of(ATTR_THREAD_NAME, threadName, ATTR_ARENA_NAME, MAIN); var attr = Attributes.of(ATTR_THREAD_NAME, threadName, ATTR_ARENA_NAME, MAIN);
var builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY_ALLOCATION); var builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY_ALLOCATION);
builder.setDescription(DESCRIPTION); builder.setDescription(DESCRIPTION);
builder.setUnit(Constants.KILOBYTES); builder.setUnit(BYTES);
histogram = builder.build().bind(attr); histogram = builder.build().bind(attr);
return this; return this;
} }

View File

@ -38,7 +38,7 @@ public final class PerThreadNetworkReadHandler implements RecordedEventHandler {
var builder = otelMeter.histogramBuilder(METRIC_NAME_BYTES); var builder = otelMeter.histogramBuilder(METRIC_NAME_BYTES);
builder.setDescription(DESCRIPTION_BYTES); builder.setDescription(DESCRIPTION_BYTES);
builder.setUnit(Constants.KILOBYTES); builder.setUnit(Constants.BYTES);
bytesHistogram = builder.build().bind(attr); bytesHistogram = builder.build().bind(attr);
builder = otelMeter.histogramBuilder(METRIC_NAME_DURATION); builder = otelMeter.histogramBuilder(METRIC_NAME_DURATION);

View File

@ -42,7 +42,7 @@ public final class PerThreadNetworkWriteHandler implements RecordedEventHandler
var builder = otelMeter.histogramBuilder(METRIC_NAME_BYTES); var builder = otelMeter.histogramBuilder(METRIC_NAME_BYTES);
builder.setDescription(DESCRIPTION_BYTES); builder.setDescription(DESCRIPTION_BYTES);
builder.setUnit(Constants.KILOBYTES); builder.setUnit(Constants.BYTES);
bytesHistogram = builder.build().bind(attr); bytesHistogram = builder.build().bind(attr);
builder = otelMeter.histogramBuilder(METRIC_NAME_DURATION); builder = otelMeter.histogramBuilder(METRIC_NAME_DURATION);