@@ -22,33 +22,33 @@ object JvmStats {
22
22
23
23
def heap = mem.getHeapMemoryUsage()
24
24
val heapStats = stats.scope(" heap" )
25
- gauges.add(heapStats.addGauge(" committed" ) { heap.getCommitted() })
26
- gauges.add(heapStats.addGauge(" max" ) { heap.getMax() })
27
- gauges.add(heapStats.addGauge(" used" ) { heap.getUsed() })
25
+ gauges.add(heapStats.addGauge(" committed" ) { heap.getCommitted().toFloat })
26
+ gauges.add(heapStats.addGauge(" max" ) { heap.getMax().toFloat })
27
+ gauges.add(heapStats.addGauge(" used" ) { heap.getUsed().toFloat })
28
28
29
29
def nonHeap = mem.getNonHeapMemoryUsage()
30
30
val nonHeapStats = stats.scope(" nonheap" )
31
- gauges.add(nonHeapStats.addGauge(" committed" ) { nonHeap.getCommitted() })
32
- gauges.add(nonHeapStats.addGauge(" max" ) { nonHeap.getMax() })
33
- gauges.add(nonHeapStats.addGauge(" used" ) { nonHeap.getUsed() })
31
+ gauges.add(nonHeapStats.addGauge(" committed" ) { nonHeap.getCommitted().toFloat })
32
+ gauges.add(nonHeapStats.addGauge(" max" ) { nonHeap.getMax().toFloat })
33
+ gauges.add(nonHeapStats.addGauge(" used" ) { nonHeap.getUsed().toFloat })
34
34
35
35
val threads = ManagementFactory .getThreadMXBean()
36
36
val threadStats = stats.scope(" thread" )
37
- gauges.add(threadStats.addGauge(" daemon_count" ) { threads.getDaemonThreadCount().toLong })
38
- gauges.add(threadStats.addGauge(" count" ) { threads.getThreadCount().toLong })
39
- gauges.add(threadStats.addGauge(" peak_count" ) { threads.getPeakThreadCount().toLong })
37
+ gauges.add(threadStats.addGauge(" daemon_count" ) { threads.getDaemonThreadCount().toFloat })
38
+ gauges.add(threadStats.addGauge(" count" ) { threads.getThreadCount().toFloat })
39
+ gauges.add(threadStats.addGauge(" peak_count" ) { threads.getPeakThreadCount().toFloat })
40
40
41
41
val runtime = ManagementFactory .getRuntimeMXBean()
42
- val uptime = stats.addGauge(" uptime" ) { runtime.getUptime() }
42
+ val uptime = stats.addGauge(" uptime" ) { runtime.getUptime().toFloat }
43
43
gauges.add(uptime)
44
- gauges.add(stats.addGauge(" start_time" ) { runtime.getStartTime() })
44
+ gauges.add(stats.addGauge(" start_time" ) { runtime.getStartTime().toFloat })
45
45
46
46
val os = ManagementFactory .getOperatingSystemMXBean()
47
- gauges.add(stats.addGauge(" num_cpus" ) { os.getAvailableProcessors().toLong })
47
+ gauges.add(stats.addGauge(" num_cpus" ) { os.getAvailableProcessors().toFloat })
48
48
os match {
49
49
case unix : com.sun.management.UnixOperatingSystemMXBean =>
50
- gauges.add(stats.addGauge(" fd_count" ) { unix.getOpenFileDescriptorCount })
51
- gauges.add(stats.addGauge(" fd_limit" ) { unix.getMaxFileDescriptorCount })
50
+ gauges.add(stats.addGauge(" fd_count" ) { unix.getOpenFileDescriptorCount.toFloat })
51
+ gauges.add(stats.addGauge(" fd_limit" ) { unix.getMaxFileDescriptorCount.toFloat })
52
52
case _ =>
53
53
}
54
54
@@ -64,15 +64,21 @@ object JvmStats {
64
64
case null =>
65
65
case compilation =>
66
66
val compilationStats = stats.scope(" compilation" )
67
- gauges.add(compilationStats.addGauge(" time_msec" ) { compilation.getTotalCompilationTime() })
67
+ gauges.add(compilationStats.addGauge(" time_msec" ) {
68
+ compilation.getTotalCompilationTime().toFloat
69
+ })
68
70
}
69
71
70
72
val classes = ManagementFactory .getClassLoadingMXBean()
71
73
val classLoadingStats = stats.scope(" classes" )
72
- gauges.add(classLoadingStats.addGauge(" total_loaded" ) { classes.getTotalLoadedClassCount() })
73
- gauges.add(classLoadingStats.addGauge(" total_unloaded" ) { classes.getUnloadedClassCount() })
74
+ gauges.add(classLoadingStats.addGauge(" total_loaded" ) {
75
+ classes.getTotalLoadedClassCount().toFloat
76
+ })
77
+ gauges.add(classLoadingStats.addGauge(" total_unloaded" ) {
78
+ classes.getUnloadedClassCount().toFloat
79
+ })
74
80
gauges.add(
75
- classLoadingStats.addGauge(" current_loaded" ) { classes.getLoadedClassCount().toLong }
81
+ classLoadingStats.addGauge(" current_loaded" ) { classes.getLoadedClassCount().toFloat }
76
82
)
77
83
78
84
val memPool = ManagementFactory .getMemoryPoolMXBeans.asScala
@@ -83,44 +89,44 @@ object JvmStats {
83
89
val name = pool.getName.regexSub(""" [^\w]""" .r) { m => " _" }
84
90
if (pool.getCollectionUsage != null ) {
85
91
def usage = pool.getCollectionUsage // this is a snapshot, we can't reuse the value
86
- gauges.add(postGCStats.addGauge(name, " used" ) { usage.getUsed })
92
+ gauges.add(postGCStats.addGauge(name, " used" ) { usage.getUsed.toFloat })
87
93
}
88
94
if (pool.getUsage != null ) {
89
95
def usage = pool.getUsage // this is a snapshot, we can't reuse the value
90
- gauges.add(currentMem.addGauge(name, " used" ) { usage.getUsed })
91
- gauges.add(currentMem.addGauge(name, " max" ) { usage.getMax })
96
+ gauges.add(currentMem.addGauge(name, " used" ) { usage.getUsed.toFloat })
97
+ gauges.add(currentMem.addGauge(name, " max" ) { usage.getMax.toFloat })
92
98
}
93
99
}
94
100
gauges.add(postGCStats.addGauge(" used" ) {
95
- memPool.flatMap(p => Option (p.getCollectionUsage)).map(_.getUsed).sum
101
+ memPool.flatMap(p => Option (p.getCollectionUsage)).map(_.getUsed).sum.toFloat
96
102
})
97
103
gauges.add(currentMem.addGauge(" used" ) {
98
- memPool.flatMap(p => Option (p.getUsage)).map(_.getUsed).sum
104
+ memPool.flatMap(p => Option (p.getUsage)).map(_.getUsed).sum.toFloat
99
105
})
100
106
101
107
// the Hotspot JVM exposes the full size that the metaspace can grow to
102
108
// which differs from the value exposed by `MemoryUsage.getMax` from above
103
109
val jvm = Jvm ()
104
110
jvm.metaspaceUsage.foreach { usage =>
105
111
gauges.add(memStats.scope(" metaspace" ).addGauge(" max_capacity" ) {
106
- usage.maxCapacity.inBytes
112
+ usage.maxCapacity.inBytes.toFloat
107
113
})
108
114
}
109
115
110
116
val spStats = stats.scope(" safepoint" )
111
- gauges.add(spStats.addGauge(" sync_time_millis" ) { jvm.safepoint.syncTimeMillis })
112
- gauges.add(spStats.addGauge(" total_time_millis" ) { jvm.safepoint.totalTimeMillis })
113
- gauges.add(spStats.addGauge(" count" ) { jvm.safepoint.count })
117
+ gauges.add(spStats.addGauge(" sync_time_millis" ) { jvm.safepoint.syncTimeMillis.toFloat })
118
+ gauges.add(spStats.addGauge(" total_time_millis" ) { jvm.safepoint.totalTimeMillis.toFloat })
119
+ gauges.add(spStats.addGauge(" count" ) { jvm.safepoint.count.toFloat })
114
120
115
121
ManagementFactory .getPlatformMXBeans(classOf [BufferPoolMXBean ]) match {
116
122
case null =>
117
123
case jBufferPool =>
118
124
val bufferPoolStats = memStats.scope(" buffer" )
119
125
jBufferPool.asScala.foreach { bp =>
120
126
val name = bp.getName
121
- gauges.add(bufferPoolStats.addGauge(name, " count" ) { bp.getCount })
122
- gauges.add(bufferPoolStats.addGauge(name, " used" ) { bp.getMemoryUsed })
123
- gauges.add(bufferPoolStats.addGauge(name, " max" ) { bp.getTotalCapacity })
127
+ gauges.add(bufferPoolStats.addGauge(name, " count" ) { bp.getCount.toFloat })
128
+ gauges.add(bufferPoolStats.addGauge(name, " used" ) { bp.getMemoryUsed.toFloat })
129
+ gauges.add(bufferPoolStats.addGauge(name, " max" ) { bp.getTotalCapacity.toFloat })
124
130
}
125
131
}
126
132
@@ -130,10 +136,10 @@ object JvmStats {
130
136
val name = gc.getName.regexSub(""" [^\w]""" .r) { m => " _" }
131
137
val poolCycles =
132
138
gcStats.metricBuilder(GaugeType ).withCounterishGauge.gauge(name, " cycles" ) {
133
- gc.getCollectionCount
139
+ gc.getCollectionCount.toFloat
134
140
}
135
141
val poolMsec = gcStats.metricBuilder(GaugeType ).withCounterishGauge.gauge(name, " msec" ) {
136
- gc.getCollectionTime
142
+ gc.getCollectionTime.toFloat
137
143
}
138
144
139
145
ExpressionSchema (s " gc_cycles " , Expression (poolCycles.metadata))
@@ -154,8 +160,12 @@ object JvmStats {
154
160
}
155
161
156
162
// note, these could be -1 if the collector doesn't have support for it.
157
- val cycles = gcStats.addGauge(" cycles" ) { gcPool.map(_.getCollectionCount).filter(_ > 0 ).sum }
158
- val msec = gcStats.addGauge(" msec" ) { gcPool.map(_.getCollectionTime).filter(_ > 0 ).sum }
163
+ val cycles = gcStats.addGauge(" cycles" ) {
164
+ gcPool.map(_.getCollectionCount).filter(_ > 0 ).sum.toFloat
165
+ }
166
+ val msec = gcStats.addGauge(" msec" ) {
167
+ gcPool.map(_.getCollectionTime).filter(_ > 0 ).sum.toFloat
168
+ }
159
169
160
170
ExpressionSchema (" jvm_uptime" , Expression (uptime.metadata))
161
171
.withLabel(ExpressionSchema .Role , " jvm" )
@@ -179,12 +189,12 @@ object JvmStats {
179
189
if (allocations.trackingEden) {
180
190
val allocationStats = memStats.scope(" allocations" )
181
191
val eden = allocationStats.scope(" eden" )
182
- gauges.add(eden.addGauge(" bytes" ) { allocations.eden })
192
+ gauges.add(eden.addGauge(" bytes" ) { allocations.eden.toFloat })
183
193
}
184
194
185
195
// return ms from ns while retaining precision
186
196
gauges.add(stats.addGauge(" application_time_millis" ) { jvm.applicationTime.toFloat / 1000000 })
187
- gauges.add(stats.addGauge(" tenuring_threshold" ) { jvm.tenuringThreshold })
197
+ gauges.add(stats.addGauge(" tenuring_threshold" ) { jvm.tenuringThreshold.toFloat })
188
198
}
189
199
190
200
}
0 commit comments