Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix units for some metrics #140

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public final class Constants {
private Constants() {}

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 KILOBYTES = "kB";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a related question for this (but not necessarily strictly the subject of this PR).

Is kB and MB are actually KiB and MiB?
See kibibyte vs. kilobyte: https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

1kB  == 1000B
1KiB == 1024B

If they are KiB/MiB, I would either change them or add some javadoc here that kB and MB are based on powers of 2 not 10 because based on the international standards 1kB is based on powers of 10).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are actually KiB and MiB. This event:

jdk.GCHeapSummary {
  startTime = 11:51:47.587
  gcId = 685
  when = "After GC"
  heapSpace = {
    start = 0x7C0000000
    committedEnd = 0x7D9300000
    committedSize = 403.0 MB
    reservedEnd = 0x800000000
    reservedSize = 1.0 GB
  }
  heapUsed = 155.7 MB
}

is actually

Used: 163273232

when read as a raw long (which actually returns bytes), and so:

jshell> 155.7 * 1024 * 1024
$2 ==> 1.632632832E8

I'll fix this - looks like we should use bytes everywhere and format for display.

public static final String MEGABYTES = "MB";
public static final String MILLISECONDS = "ms";
public static final String PERCENTAGE = "%age";
public static final String READ = "read";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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.contrib.jfr.metrics.internal.RecordedEventHandler;
Expand All @@ -28,7 +28,7 @@ public ContextSwitchRateHandler init() {
otelMeter
.upDownCounterBuilder(METRIC_NAME)
.ofDoubles()
.setUnit(ONE)
.setUnit(HERTZ)
.buildWithCallback(codm -> codm.observe(value));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.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.USER;

Expand Down Expand Up @@ -43,7 +44,7 @@ public OverallCPULoadHandler init() {
var attr = Attributes.of(ATTR_CPU_USAGE, USER);
var builder = otelMeter.histogramBuilder(METRIC_NAME);
builder.setDescription(DESCRIPTION);
builder.setUnit(ONE);
builder.setUnit(PERCENTAGE);
userHistogram = builder.build().bind(attr);

attr = Attributes.of(ATTR_CPU_USAGE, SYSTEM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.ATTR_MEMORY_USAGE;
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.MEGABYTES;
import static io.opentelemetry.contrib.jfr.metrics.internal.Constants.USED;

import io.opentelemetry.api.common.Attributes;
Expand Down Expand Up @@ -57,13 +57,13 @@ public GCHeapSummaryHandler init() {
var attr = Attributes.of(ATTR_MEMORY_USAGE, USED);
builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY);
builder.setDescription(DESCRIPTION);
builder.setUnit(KILOBYTES);
builder.setUnit(MEGABYTES);
usedHistogram = builder.build().bind(attr);

attr = Attributes.of(ATTR_MEMORY_USAGE, COMMITTED);
builder = otelMeter.histogramBuilder(METRIC_NAME_MEMORY);
builder.setDescription(DESCRIPTION);
builder.setUnit(KILOBYTES);
builder.setUnit(MEGABYTES);
committedHistogram = builder.build().bind(attr);

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PerThreadNetworkReadHandler init() {

var builder = otelMeter.histogramBuilder(METRIC_NAME_BYTES);
builder.setDescription(DESCRIPTION_BYTES);
builder.setUnit(Constants.KILOBYTES);
builder.setUnit(Constants.BYTES);
bytesHistogram = builder.build().bind(attr);

builder = otelMeter.histogramBuilder(METRIC_NAME_DURATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PerThreadNetworkWriteHandler init() {

var builder = otelMeter.histogramBuilder(METRIC_NAME_BYTES);
builder.setDescription(DESCRIPTION_BYTES);
builder.setUnit(Constants.KILOBYTES);
builder.setUnit(Constants.BYTES);
bytesHistogram = builder.build().bind(attr);

builder = otelMeter.histogramBuilder(METRIC_NAME_DURATION);
Expand Down