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

Add meter type to JSON metrics metadata output #8057

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 14 additions & 17 deletions docs/includes/guides/metrics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,20 @@ You can get the metadata for any scope, such as `{metrics-endpoint}?scope=base`,
.JSON response (truncated):
----
{
"classloader.currentLoadedClass.count": {
"unit": "none",
"type": "counter",
"description": "Displays the number of classes that are currently loaded in the Java virtual machine."
},
"jvm.uptime": {
"unit": "milliseconds",
"type": "gauge",
"description": "Displays the start time of the Java virtual machine in milliseconds. This attribute displays the approximate time when the Java virtual machine started.",
"displayName": "JVM Uptime"
},
"memory.usedHeap": {
"unit": "bytes",
"type": "gauge",
"description": "Displays the amount of used heap memory in bytes.",
"displayName": "Used Heap Memory"
}
"classloader.loadedClasses.count": {
"type": "gauge",
"description": "Displays the number of classes that are currently loaded in the Java virtual machine."
},
"jvm.uptime": {
"type": "gauge",
"unit": "seconds",
"description": "Displays the start time of the Java virtual machine in milliseconds. This attribute displays the approximate time when the Java virtual machine started."
},
"memory.usedHeap": {
"type": "gauge",
"unit": "bytes",
"description": "Displays the amount of used heap memory in bytes."
}
}
----

Expand Down
10 changes: 10 additions & 0 deletions metrics/api/src/main/java/io/helidon/metrics/api/Meter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.helidon.metrics.api;

import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -90,6 +91,15 @@ enum Type {
*/
OTHER;

/**
* Type name suitable for metadata output.
*
* @return name of the type formatted for human output
*/
public String typeName() {
return name().toLowerCase(Locale.ROOT);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ && matchesName(name)) {

JsonObjectBuilder builderForThisName = metadataOutputBuilderWithinParent
.computeIfAbsent(name, k -> JSON.createObjectBuilder());
addNonEmpty(builderForThisName, "type", meter.type().typeName());
meter.baseUnit().ifPresent(u -> addNonEmpty(builderForThisName, "unit", u));
meter.description().ifPresent(d -> addNonEmpty(builderForThisName, "description", d));
isAnyOutput.set(true);
Expand Down