Skip to content

Commit c28bb9f

Browse files
authored
Update JavaFlightRecorder.java
Hold reference to thread count gauges
1 parent 37d39fc commit c28bb9f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

spectator-ext-jvm/src/main/java17/com/netflix/spectator/jvm/JavaFlightRecorder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,16 @@ private static void collectCompilerStatistics(Registry registry, RecordingStream
9696
}
9797

9898
private static void collectThreadStatistics(Registry registry, RecordingStream rs) {
99+
Gauge nonDaemonThreadCount = registry.gauge("jvm.thread.threadCount", "id", "non-daemon");
100+
Gauge daemonThreadCount = registry.gauge("jvm.thread.threadCount", "id", "daemon");
99101
Counter threadsStarted = registry.counter("jvm.thread.threadsStarted");
100102
AtomicLong prevAccumulatedCount = new AtomicLong();
101103
consume(JavaThreadStatistics, rs, event -> {
102104
long activeCount = event.getLong("activeCount");
103105
long daemonCount = event.getLong("daemonCount");
104106
long nonDaemonCount = activeCount - daemonCount;
105-
registry.gauge("jvm.thread.threadCount", "id", "non-daemon").set(nonDaemonCount);
106-
registry.gauge("jvm.thread.threadCount", "id", "daemon").set(daemonCount);
107+
nonDaemonThreadCount.set(nonDaemonCount);
108+
daemonThreadCount.set(daemonCount);
107109
long accumulatedCount = event.getLong("accumulatedCount");
108110
accumulatedCount = accumulatedCount - prevAccumulatedCount.getAndSet(accumulatedCount);
109111
threadsStarted.increment(accumulatedCount);
@@ -126,8 +128,8 @@ private static void collectGcEvents(Registry registry, RecordingStream rs) {
126128
// ZGC and Shenandoah are not covered by the generic event, there is
127129
// a ZGC specific event to get coverage there, right now there doesn't
128130
// appear to be similar data available for Shenandoah
129-
Gauge tenuringThreshold = registry.gauge("jvm.gc.tenuringThreshold");
130-
Consumer<RecordedEvent> tenuringThresholdFn = event ->
131+
Gauge tenuringThreshold = registry.gauge("jvm.gc.tenuringThreshold");
132+
Consumer<RecordedEvent> tenuringThresholdFn = event ->
131133
tenuringThreshold.set(event.getLong("tenuringThreshold"));
132134
consume(YoungGarbageCollection, rs, tenuringThresholdFn);
133135
consume(ZYoungGarbageCollection, rs, tenuringThresholdFn);

0 commit comments

Comments
 (0)