diff options
author | Pavel Kazlou <pavel.kazlou@adform.com> | 2015-01-09 20:38:44 +0300 |
---|---|---|
committer | Pavel Kazlou <pavel.kazlou@adform.com> | 2015-01-09 20:38:44 +0300 |
commit | cc21bb2b9261014cec9ce13aa71cfd44532236bd (patch) | |
tree | 1b4f95c1379e5548a70c60f5a51d5de0b8f4d02c /kamon-system-metrics | |
parent | 4a47e92d23af371f1d50b40af6cbe00a5ffc0105 (diff) | |
download | Kamon-cc21bb2b9261014cec9ce13aa71cfd44532236bd.tar.gz Kamon-cc21bb2b9261014cec9ce13aa71cfd44532236bd.tar.bz2 Kamon-cc21bb2b9261014cec9ce13aa71cfd44532236bd.zip |
system-metrics: fix #148, file descriptor leak in context switches
Diffstat (limited to 'kamon-system-metrics')
-rw-r--r-- | kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala b/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala index 4391240a..5cb017ce 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala @@ -16,6 +16,8 @@ package kamon.system import java.io.{ File, IOException } +import java.nio.charset.StandardCharsets +import java.nio.file.{Paths, Files} import akka.actor.{ Actor, ActorLogging, Props } import kamon.Kamon @@ -33,8 +35,9 @@ import org.hyperic.sigar._ import scala.collection.concurrent.TrieMap import scala.concurrent.duration.FiniteDuration -import scala.io.Source import scala.collection.mutable +import scala.collection.JavaConverters.iterableAsScalaIterableConverter + class SystemMetricsCollector(collectInterval: FiniteDuration) extends Actor with ActorLogging with SystemMetricsBanner { import kamon.system.SystemMetricsCollector._ @@ -169,7 +172,7 @@ class SystemMetricsCollector(collectInterval: FiniteDuration) extends Actor with var nonVoluntaryContextSwitches = 0L try { - for (line ← Source.fromFile(filename).getLines()) { + for (line <- Files.readAllLines(Paths.get(filename), StandardCharsets.US_ASCII).asScala.toList) { if (line.startsWith("voluntary_ctxt_switches")) { voluntaryContextSwitches = line.substring(line.indexOf(":") + 1).trim.toLong } @@ -188,7 +191,7 @@ class SystemMetricsCollector(collectInterval: FiniteDuration) extends Actor with var contextSwitches = 0L try { - for (line ← Source.fromFile(filename).getLines()) { + for (line <- Files.readAllLines(Paths.get(filename), StandardCharsets.US_ASCII).asScala.toList) { if (line.startsWith("rcs")) { contextSwitches = line.substring(line.indexOf(" ") + 1).toLong } |