Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class JvmGcMetrics implements MeterBinder, AutoCloseable {

private final boolean managementExtensionsPresent = isManagementExtensionsPresent();

private final boolean garbageCollectorNotificationsAvailable = isGarbageCollectorNotificationsAvailable();

// VisibleForTesting
final boolean isGenerationalGc = isGenerationalGcConfigured();

Expand Down Expand Up @@ -119,7 +121,7 @@ public JvmGcMetrics(Iterable<Tag> tags) {

@Override
public void bindTo(MeterRegistry registry) {
if (!this.managementExtensionsPresent) {
if (!this.managementExtensionsPresent || !this.garbageCollectorNotificationsAvailable) {
return;
}

Expand Down Expand Up @@ -325,6 +327,27 @@ private static boolean isManagementExtensionsPresent() {
}
}

private static boolean isGarbageCollectorNotificationsAvailable() {
List<String> gcsWithoutNotification = new ArrayList<>();
for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
if (!(gcBean instanceof NotificationEmitter)) {
continue;
}
NotificationEmitter notificationEmitter = (NotificationEmitter) gcBean;
boolean notificationAvailable = Arrays.stream(notificationEmitter.getNotificationInfo())
.anyMatch(mBeanNotificationInfo -> Arrays.asList(mBeanNotificationInfo.getNotifTypes())
.contains(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION));
if (notificationAvailable) {
return true;
}
gcsWithoutNotification.add(gcBean.getName());
}
log.warn("GC notifications will not be available because no GarbageCollectorMXBean of the JVM provides any."
+ " GCs=" + gcsWithoutNotification);

return false;
}

@Override
public void close() {
notificationListenerCleanUpRunnables.forEach(Runnable::run);
Expand Down