diff options
author | Diego <diegolparra@gmail.com> | 2015-05-06 13:01:41 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2015-05-06 13:01:41 -0300 |
commit | bda62b69b530f48cba8d4a2d0eeb1b0e85953b5e (patch) | |
tree | b54456981fe0489ec2c9a748b846d9160a8cebf4 /kamon-system-metrics/src/main/scala/kamon/system/sigar | |
parent | 53d109984ece3d51e3295bd3e6b2d06f3d05787f (diff) | |
download | Kamon-bda62b69b530f48cba8d4a2d0eeb1b0e85953b5e.tar.gz Kamon-bda62b69b530f48cba8d4a2d0eeb1b0e85953b5e.tar.bz2 Kamon-bda62b69b530f48cba8d4a2d0eeb1b0e85953b5e.zip |
= system-metrics: avoid division by zero exception and close #194
Diffstat (limited to 'kamon-system-metrics/src/main/scala/kamon/system/sigar')
-rw-r--r-- | kamon-system-metrics/src/main/scala/kamon/system/sigar/ProcessCpuMetrics.scala | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/ProcessCpuMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/ProcessCpuMetrics.scala index 4432e6cd..43b6ba83 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/ProcessCpuMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/ProcessCpuMetrics.scala @@ -20,6 +20,8 @@ import kamon.metric.GenericEntityRecorder import kamon.metric.instrument.InstrumentFactory import org.hyperic.sigar.{ ProcCpu, Sigar } +import scala.util.Try + /** * Process Cpu usage metrics, as reported by Sigar: * - user: Process cpu user time. @@ -51,7 +53,7 @@ class ProcessCpuMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) exte val systemDiff = currentProcCpu.getSys - lastProcCpu.getSys val timeDiff = currentProcCpu.getLastTime - lastProcCpu.getLastTime - def percentUsage(delta: Long): Long = 100 * delta / timeDiff / totalCores + def percentUsage(delta: Long): Long = Try(100 * delta / timeDiff / totalCores).getOrElse(0L) if (totalDiff == 0) { if (timeDiff > 2000) currentLoad = 0 |