blob: 34a23d4f5677ef43b118c7f9480458a7fa85a4a3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package kamon.system.jmx
import java.lang.management.ManagementFactory
import kamon.metric.GenericEntityRecorder
import kamon.metric.instrument.{ Memory, InstrumentFactory }
class NonHeapMemoryMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) {
val memoryBean = ManagementFactory.getMemoryMXBean
def nonHeapUsage = memoryBean.getNonHeapMemoryUsage
gauge("non-heap-used", Memory.Bytes, () ⇒ {
nonHeapUsage.getUsed
})
gauge("non-heap-max", Memory.Bytes, () ⇒ {
val max = nonHeapUsage.getMax
// .getMax can return -1 if the max is not defined.
if (max >= 0) max
else 0
})
gauge("non-heap-committed", Memory.Bytes, () ⇒ {
nonHeapUsage.getCommitted
})
}
object NonHeapMemoryMetrics extends JmxSystemMetricRecorderCompanion("non-heap-memory") {
def apply(instrumentFactory: InstrumentFactory): NonHeapMemoryMetrics =
new NonHeapMemoryMetrics(instrumentFactory)
}
|