Skip to content

Commit

Permalink
Use Flight Recorder when registerStandardMXBeans is called
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielThomas committed Sep 3, 2024
1 parent fdf7d82 commit 6f70c0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 11 additions & 0 deletions spectator-ext-jvm/src/main/java/com/netflix/spectator/jvm/Jmx.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.ThreadMXBean;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
* Helpers for working with JMX mbeans.
Expand All @@ -42,6 +44,15 @@ private Jmx() {
* mbeans from the local jvm.
*/
public static void registerStandardMXBeans(Registry registry) {
if (JavaFlightRecorder.isSupported()) {
Executor executor = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r, "spectator-jfr");
t.setDaemon(true);
return t;
});
JavaFlightRecorder.monitorDefaultEvents(registry, executor);
return;
}
monitorClassLoadingMXBean(registry);
monitorThreadMXBean(registry);
monitorCompilationMXBean(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ public void checkDefaultMeasures() throws Exception {
executor.shutdownNow();

Map<Id, Measurement> measures = registry.measurements()
.collect(Collectors.toMap(Measurement::id, m -> m));

Measurement tenuringThreshold = measures.get(Id.create("jvm.gc.tenuringThreshold"));
assertNotEquals(null, tenuringThreshold);
assertTrue(tenuringThreshold.value() > 0);
.collect(Collectors.toMap(Measurement::id, m -> m));gd

Measurement classesLoaded = measures.get(Id.create("jvm.classloading.classesLoaded"));
Measurement classesUnloaded = measures.get(Id.create("jvm.classloading.classesUnloaded"));
Expand Down

0 comments on commit 6f70c0a

Please sign in to comment.