Skip to content

Commit

Permalink
Quarkus: Avoid binding metrics unsupported by the VM
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin Schnabel authored and Jon Schneider committed Mar 27, 2020
1 parent e308d08 commit 6635860
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public void bindTo(MeterRegistry registry) {
}

private static boolean isManagementExtensionsPresent() {
if ( ManagementFactory.getMemoryPoolMXBeans().isEmpty() ) {
// Substrate VM, for example, doesn't provide or support these beans (yet)
log.warn("GC notifications will not be available because MemoryPoolMXBeans are not provided by the JVM");
return false;
}

try {
Class.forName("com.sun.management.GarbageCollectionNotificationInfo", false,
JvmGcMetrics.class.getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ public void bindTo(MeterRegistry registry) {
.baseUnit(BaseUnits.THREADS)
.register(registry);

for (Thread.State state : Thread.State.values()) {
Gauge.builder("jvm.threads.states", threadBean, (bean) -> getThreadStateCount(bean, state))
.tags(Tags.concat(tags, "state", getStateTagValue(state)))
.description("The current number of threads having " + state + " state")
.baseUnit(BaseUnits.THREADS)
.register(registry);
try {
threadBean.getAllThreadIds();
for (Thread.State state : Thread.State.values()) {
Gauge.builder("jvm.threads.states", threadBean, (bean) -> getThreadStateCount(bean, state))
.tags(Tags.concat(tags, "state", getStateTagValue(state)))
.description("The current number of threads having " + state + " state")
.baseUnit(BaseUnits.THREADS)
.register(registry);
}
} catch (Error error) {
// An error will be thrown for unsupported operations
// e.g. SubstrateVM does not support getAllThreadIds
}
}

Expand Down

0 comments on commit 6635860

Please sign in to comment.