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 5b74da6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 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 @@ -58,10 +58,6 @@ public void checkDefaultMeasures() throws Exception {
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);

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

0 comments on commit 5b74da6

Please sign in to comment.