15
15
*/
16
16
package com .netflix .spectator .jvm ;
17
17
18
+ import com .netflix .spectator .api .Counter ;
19
+ import com .netflix .spectator .api .Gauge ;
18
20
import com .netflix .spectator .api .Registry ;
21
+ import com .netflix .spectator .api .Timer ;
19
22
import jdk .jfr .EventSettings ;
20
23
import jdk .jfr .consumer .RecordedEvent ;
21
24
import jdk .jfr .consumer .RecordingStream ;
@@ -67,29 +70,33 @@ public static AutoCloseable monitorDefaultEvents(Registry registry, Executor exe
67
70
}
68
71
69
72
private static void collectClassLoadingStatistics (Registry registry , RecordingStream rs ) {
73
+ Counter classesLoaded = registry .counter ("jvm.classloading.classesLoaded" );
70
74
AtomicLong prevLoadedClassCount = new AtomicLong ();
75
+ Counter classesUnloaded = registry .counter ("jvm.classloading.classesUnloaded" );
71
76
AtomicLong prevUnloadedClassCount = new AtomicLong ();
72
77
consume (ClassLoadingStatistics , rs , event -> {
73
- long classesLoaded = event .getLong ("loadedClassCount" );
74
- classesLoaded = classesLoaded - prevLoadedClassCount .getAndSet (classesLoaded );
75
- registry . counter ( "jvm.classloading. classesLoaded" ) .increment (classesLoaded );
78
+ long loadedClassCount = event .getLong ("loadedClassCount" );
79
+ loadedClassCount = loadedClassCount - prevLoadedClassCount .getAndSet (loadedClassCount );
80
+ classesLoaded .increment (loadedClassCount );
76
81
77
- long classesUnloaded = event .getLong ("unloadedClassCount" );
78
- classesUnloaded = classesUnloaded - prevUnloadedClassCount .getAndSet (classesUnloaded );
79
- registry . counter ( "jvm.classloading. classesUnloaded" ) .increment (classesUnloaded );
82
+ long unloadedClassCount = event .getLong ("unloadedClassCount" );
83
+ unloadedClassCount = unloadedClassCount - prevUnloadedClassCount .getAndSet (unloadedClassCount );
84
+ classesUnloaded .increment (unloadedClassCount );
80
85
});
81
86
}
82
87
83
88
private static void collectCompilerStatistics (Registry registry , RecordingStream rs ) {
89
+ Counter compilationTime = registry .counter ("jvm.compilation.compilationTime" );
84
90
AtomicLong prevTotalTimeSpent = new AtomicLong ();
85
91
consume (CompilerStatistics , rs , event -> {
86
92
long totalTimeSpent = event .getLong ("totalTimeSpent" );
87
93
totalTimeSpent = totalTimeSpent - prevTotalTimeSpent .getAndAdd (totalTimeSpent );
88
- registry . counter ( "jvm.compilation. compilationTime" ) .add (totalTimeSpent / 1000.0 );
94
+ compilationTime .add (totalTimeSpent / 1000.0 );
89
95
});
90
96
}
91
97
92
98
private static void collectThreadStatistics (Registry registry , RecordingStream rs ) {
99
+ Counter threadsStarted = registry .counter ("jvm.thread.threadsStarted" );
93
100
AtomicLong prevAccumulatedCount = new AtomicLong ();
94
101
consume (JavaThreadStatistics , rs , event -> {
95
102
long activeCount = event .getLong ("activeCount" );
@@ -98,30 +105,32 @@ private static void collectThreadStatistics(Registry registry, RecordingStream r
98
105
registry .gauge ("jvm.thread.threadCount" , "id" , "non-daemon" ).set (nonDaemonCount );
99
106
registry .gauge ("jvm.thread.threadCount" , "id" , "daemon" ).set (daemonCount );
100
107
long accumulatedCount = event .getLong ("accumulatedCount" );
101
- long threadsStarted = accumulatedCount - prevAccumulatedCount .getAndSet (accumulatedCount );
102
- registry . counter ( "jvm.thread. threadsStarted" ) .increment (threadsStarted );
108
+ accumulatedCount = accumulatedCount - prevAccumulatedCount .getAndSet (accumulatedCount );
109
+ threadsStarted .increment (accumulatedCount );
103
110
});
104
111
}
105
112
106
113
private static void collectVirtualThreadEvents (Registry registry , RecordingStream rs ) {
114
+ Timer pinned = registry .timer ("jvm.vt.pinned" );
115
+ Counter submitFailed = registry .counter ("jvm.vt.submitFailed" );
107
116
// 20ms threshold set to match default behavior
108
117
consume (VirtualThreadPinned , rs , event ->
109
- registry . timer ( "jvm.vt. pinned" ) .record (event .getDuration ())
118
+ pinned .record (event .getDuration ())
110
119
).withThreshold (Duration .ofMillis (20 ));
111
120
consume (VirtualThreadSubmitFailed , rs , event ->
112
- registry . counter ( "jvm.vt. submitFailed" ) .increment ()
121
+ submitFailed .increment ()
113
122
);
114
123
}
115
124
116
125
private static void collectGcEvents (Registry registry , RecordingStream rs ) {
117
126
// ZGC and Shenandoah are not covered by the generic event, there is
118
127
// a ZGC specific event to get coverage there, right now there doesn't
119
128
// appear to be similar data available for Shenandoah
120
- Consumer < RecordedEvent > tenuringThreshold = event ->
121
- registry . gauge ( "jvm.gc.tenuringThreshold" )
122
- .set (event .getLong ("tenuringThreshold" ));
123
- consume (YoungGarbageCollection , rs , tenuringThreshold );
124
- consume (ZYoungGarbageCollection , rs , tenuringThreshold );
129
+ Gauge tenuringThreshold = registry . gauge ( "jvm.gc.tenuringThreshold" );
130
+ Consumer < RecordedEvent > tenuringThresholdFn = event ->
131
+ tenuringThreshold .set (event .getLong ("tenuringThreshold" ));
132
+ consume (YoungGarbageCollection , rs , tenuringThresholdFn );
133
+ consume (ZYoungGarbageCollection , rs , tenuringThresholdFn );
125
134
126
135
consume (ZAllocationStall , rs , event ->
127
136
registry .timer ("jvm.gc.allocationStall" , "type" , event .getString ("type" ))
0 commit comments