You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Currently, the JVM class unloading metric is being registered as a Function counter. The description says "The total number of classes unloaded since the Java virtual machine has started execution" which will not be true when this metric is used in a Step Meter Registry.
Environment
Micrometer version - Any version
Micrometer registry - Any Step Registry can be used
OS: Any
Java version: Any
To Reproduce
How to reproduce the bug:
Start the java application with the micrometer JVM binder enabled. Use any step registry to register these metrics. After one step is completed, the unloaded class becomes zero.
Expected behavior
jvm.classes.unloaded - should represent the total number of classes unloaded since the Java virtual machine has started execution
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Update the description of jvm.classes.unloaded to make the statement valid for Step registries. Currently, it says "classes loaded from JVM start" but this will not be true for a StepRegistry.
Add a metric to report total classes loaded from ClassLoadingMXBean#getTotalLoadedClassCount. Ideally, this metric should be named "jvm.classes.loaded" but we already have a metric with the same name. We need to sort that out.
I think there is an open question on how we handle the names,
jvm.classes.unloaded - is a sorted thing.
The opposite of this metric would be jvm.classes.loaded using info from ClassLoadingMXBean#getTotalLoadedClassCount but that name is already taken.
Today, we already have a metric named jvm.classes.loaded which reports the number of classes loaded currently. Ideally, this should have been jvm.classes.count or jvm.classes.current.count. I am not sure how will be able to handle this change. This will be a breaking change but in metric space emitting a metric with the same name but representing different info would be very dangerous.
jvm.classes.unloaded for a counter of total unloaded classes
jvm.classes.loaded would be the number of classes currently loaded
jvm.classes.loaded.count could be the counter of total loaded classes
Now if someone wants to be OTel compliant they can create a MeterFilter and rename the metrics. If we decide one day that we want to migrate that will also mean that we would have to provide such a MeterFilter and give users a couple of minor versions to migrate to it and then change the names in core and deprecate the MeterFilter.
After it is merged, snapshots are published for each commit, but the M3 release was made shortly after the mentioned PR was merged, so the milestone is already available.
Activity
lenin-jaganathan commentedon Dec 9, 2022
I am not sure such behavior was created. But ideally, using the below snippet for class unloading will help solve this issue.I see that jvm.classes.loaded metric is the number of classes that are loaded currently and this being a gauge makes sense.
jvm.classes.unloaded - is the total number of classes unloaded since the JVM has started, so this should not be a gauge but rather a counter.
Will it be informational to also expose "the total number of classes loaded" by the JVM?
patpatpat123 commentedon Dec 22, 2023
Upvoting this
marcingrzejszczak commentedon Dec 27, 2023
Some questions:
jvm.classes.loadedis a gaugejvm.classes.unloadedis a counter not a gauge, right?So is this issue about adding the "the total number of classes loaded" ? Are you upvoting this @patpatpat123 ?
patpatpat123 commentedon Dec 30, 2023
Hello @marcingrzejszczak ,
Thank you for your input.
First of all, you are correct about the two metrics:
And yes, it would be great to have metrics unifying those, to allow building visuals such as a loaded vs. unloaded counter.
github-actions commentedon Jan 7, 2024
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
lenin-jaganathan commentedon Jan 8, 2024
I am voting for the below 2 things,
jvm.classes.unloadedto make the statement valid for Step registries. Currently, it says "classes loaded from JVM start" but this will not be true for a StepRegistry.ClassLoadingMXBean#getTotalLoadedClassCount. Ideally, this metric should be named "jvm.classes.loaded" but we already have a metric with the same name. We need to sort that out.marcingrzejszczak commentedon Jan 10, 2024
Thanks for the update. Are you willing to file a PR for this @lenin-jaganathan ?
lenin-jaganathan commentedon Jan 12, 2024
I think there is an open question on how we handle the names,
jvm.classes.unloaded- is a sorted thing.The opposite of this metric would be
jvm.classes.loadedusing info fromClassLoadingMXBean#getTotalLoadedClassCountbut that name is already taken.Today, we already have a metric named
jvm.classes.loadedwhich reports the number of classes loaded currently. Ideally, this should have beenjvm.classes.countorjvm.classes.current.count. I am not sure how will be able to handle this change. This will be a breaking change but in metric space emitting a metric with the same name but representing different info would be very dangerous.Also see what OTEL does in this space.
marcingrzejszczak commentedon Jan 12, 2024
We could do sth like this
jvm.classes.unloadedfor a counter of total unloaded classesjvm.classes.loadedwould be the number of classes currently loadedjvm.classes.loaded.countcould be the counter of total loaded classesNow if someone wants to be OTel compliant they can create a
MeterFilterand rename the metrics. If we decide one day that we want to migrate that will also mean that we would have to provide such aMeterFilterand give users a couple of minor versions to migrate to it and then change the names in core and deprecate theMeterFilter.WDYT @shakuzen @jonatan-ivanov ?
24 remaining items
shakuzen commentedon Sep 9, 2025
This has been resolved by #6682 (comment)
patpatpat123 commentedon Sep 9, 2025
Many thanks for all of you.
To test this, I need to wait for this to be released right?
shakuzen commentedon Sep 9, 2025
After it is merged, snapshots are published for each commit, but the M3 release was made shortly after the mentioned PR was merged, so the milestone is already available.