diff options
author | Diego <diegolparra@gmail.com> | 2015-08-11 01:29:56 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2015-08-11 01:29:56 -0300 |
commit | 1e8b589267b66ea04d3bf15a8f9f28c34d4832d9 (patch) | |
tree | 1a5ed67a297259852cfc2c14a49c5bdee26d8c68 /kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala | |
parent | 820e96c9db1ecb2a88bcfb81f57f7f0c14d47f78 (diff) | |
download | Kamon-1e8b589267b66ea04d3bf15a8f9f28c34d4832d9.tar.gz Kamon-1e8b589267b66ea04d3bf15a8f9f28c34d4832d9.tar.bz2 Kamon-1e8b589267b66ea04d3bf15a8f9f28c34d4832d9.zip |
= system-metrics: The sigar not implemented exceptions are listed as warnings. closes #235
Diffstat (limited to 'kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala')
-rw-r--r-- | kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala index 0e9a5b53..54b95ab7 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala @@ -16,6 +16,7 @@ package kamon.system.sigar +import akka.event.LoggingAdapter import kamon.metric.GenericEntityRecorder import kamon.metric.instrument.InstrumentFactory import org.hyperic.sigar.Sigar @@ -28,7 +29,7 @@ import org.hyperic.sigar.Sigar * - idle: Total percentage of system cpu idle time * - stolen: Total percentage of system cpu involuntary wait time. @see [[https://www.datadoghq.com/2013/08/understanding-aws-stolen-cpu-and-how-it-affects-your-apps/ "Understanding Stolen Cpu"]] */ -class CpuMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class CpuMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory, logger: LoggingAdapter) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val user = histogram("cpu-user") val system = histogram("cpu-system") val Wait = histogram("cpu-wait") @@ -36,18 +37,29 @@ class CpuMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends Gen val stolen = histogram("cpu-stolen") def update(): Unit = { - val cpuPerc = sigar.getCpuPerc + import SigarSafeRunner._ - user.record((cpuPerc.getUser * 100L).toLong) - system.record((cpuPerc.getSys * 100L).toLong) - Wait.record((cpuPerc.getWait * 100L).toLong) - idle.record((cpuPerc.getIdle * 100L).toLong) - stolen.record((cpuPerc.getStolen * 100L).toLong) + def cpuPerc = { + val cpuPerc = sigar.getCpuPerc + ((cpuPerc.getUser * 100L).toLong, + (cpuPerc.getSys * 100L).toLong, + (cpuPerc.getWait * 100L).toLong, + (cpuPerc.getIdle * 100L).toLong, + (cpuPerc.getStolen * 100L).toLong) + } + + val (cpuUser, cpuSys, cpuWait, cpuIdle, cpuStolen) = runSafe(cpuPerc, (0L, 0L, 0L, 0L, 0L), "cpu", logger) + + user.record(cpuUser) + system.record(cpuSys) + Wait.record(cpuWait) + idle.record(cpuIdle) + stolen.record(cpuStolen) } } object CpuMetrics extends SigarMetricRecorderCompanion("cpu") { - def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): CpuMetrics = - new CpuMetrics(sigar, instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory, logger: LoggingAdapter): CpuMetrics = + new CpuMetrics(sigar, instrumentFactory, logger) } |