From affe465fdcc002fb12c54b3bb139ba3ef4fb1d85 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 3 Mar 2016 00:47:53 -0300 Subject: = system-metrics: runSafe in UlimitMetrics and include a test --- .../test/scala/kamon/metric/MetricScaleDecoratorSpec.scala | 6 +++--- .../test/scala/kamon/metric/instrument/HistogramSpec.scala | 8 ++++---- .../kamon/metric/instrument/UnitOfMeasurementSpec.scala | 2 +- kamon-core/src/test/scala/kamon/util/NeedToScaleSpec.scala | 12 ++++++------ .../src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala | 6 ++---- .../src/main/scala/kamon/system/sigar/ULimitMetrics.scala | 6 ++++-- .../src/test/scala/kamon/metrics/SystemMetricsSpec.scala | 6 ++++++ 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/kamon-core/src/test/scala/kamon/metric/MetricScaleDecoratorSpec.scala b/kamon-core/src/test/scala/kamon/metric/MetricScaleDecoratorSpec.scala index 04821923..902102cd 100644 --- a/kamon-core/src/test/scala/kamon/metric/MetricScaleDecoratorSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/MetricScaleDecoratorSpec.scala @@ -18,7 +18,7 @@ package kamon.metric import kamon.Kamon import kamon.metric.SubscriptionsDispatcher.TickMetricSnapshot -import kamon.metric.instrument.{InstrumentFactory, Memory, Time, UnitOfMeasurement} +import kamon.metric.instrument.{ InstrumentFactory, Memory, Time, UnitOfMeasurement } import kamon.testkit.BaseKamonSpec import kamon.util.MilliTimestamp import org.scalatest.OptionValues._ @@ -62,10 +62,10 @@ class MetricScaleDecoratorSpec extends BaseKamonSpec("metrics-scale-decorator-sp } trait SnapshotFixtures { - self: BaseKamonSpec => + self: BaseKamonSpec ⇒ class ScaleDecoratorTestMetrics(instrumentFactory: InstrumentFactory) - extends GenericEntityRecorder(instrumentFactory) { + extends GenericEntityRecorder(instrumentFactory) { val nanoTime = histogram("nano-time", Time.Nanoseconds) val microTime = counter("micro-time", Time.Microseconds) val byteMemory = histogram("byte-memory", Memory.Bytes) diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala index ff71cd56..adfcd826 100644 --- a/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala @@ -64,8 +64,8 @@ class HistogramSpec extends WordSpec with Matchers { snapshot.sum should be(41300) snapshot.numberOfMeasurements should be(203) - val records = snapshot.recordsIterator.map(r => r.level -> r.count).toSeq - records.size should be (4) + val records = snapshot.recordsIterator.map(r ⇒ r.level -> r.count).toSeq + records.size should be(4) records(0) should be(100 -> 1) records(1) should be(200 -> 200) records(2) should be(300 -> 1) @@ -88,8 +88,8 @@ class HistogramSpec extends WordSpec with Matchers { snapshot.sum should be(41300000) snapshot.numberOfMeasurements should be(203) - val records = snapshot.recordsIterator.map(r => r.level -> r.count).toSeq - records.size should be (4) + val records = snapshot.recordsIterator.map(r ⇒ r.level -> r.count).toSeq + records.size should be(4) records(0) should be(100000 -> 1) records(1) should be(200000 -> 200) records(2) should be(300000 -> 1) diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/UnitOfMeasurementSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/UnitOfMeasurementSpec.scala index 7133579e..10604fe5 100644 --- a/kamon-core/src/test/scala/kamon/metric/instrument/UnitOfMeasurementSpec.scala +++ b/kamon-core/src/test/scala/kamon/metric/instrument/UnitOfMeasurementSpec.scala @@ -17,7 +17,7 @@ package kamon.metric.instrument import kamon.metric.instrument.UnitOfMeasurement.Unknown -import org.scalatest.{Matchers, WordSpec} +import org.scalatest.{ Matchers, WordSpec } class UnitOfMeasurementSpec extends WordSpec with Matchers { diff --git a/kamon-core/src/test/scala/kamon/util/NeedToScaleSpec.scala b/kamon-core/src/test/scala/kamon/util/NeedToScaleSpec.scala index 3486a60c..a53451b6 100644 --- a/kamon-core/src/test/scala/kamon/util/NeedToScaleSpec.scala +++ b/kamon-core/src/test/scala/kamon/util/NeedToScaleSpec.scala @@ -17,8 +17,8 @@ package kamon.util import com.typesafe.config.ConfigFactory -import kamon.metric.instrument.{Memory, Time} -import org.scalatest.{Matchers, WordSpec} +import kamon.metric.instrument.{ Memory, Time } +import org.scalatest.{ Matchers, WordSpec } class NeedToScaleSpec extends WordSpec with Matchers { @@ -30,7 +30,7 @@ class NeedToScaleSpec extends WordSpec with Matchers { """.stripMargin) config match { - case NeedToScale(timeUnits, memoryUnits) => + case NeedToScale(timeUnits, memoryUnits) ⇒ timeUnits should be(Some(Time.Milliseconds)) memoryUnits should be(None) } @@ -42,7 +42,7 @@ class NeedToScaleSpec extends WordSpec with Matchers { """.stripMargin) config match { - case NeedToScale(timeUnits, memoryUnits) => + case NeedToScale(timeUnits, memoryUnits) ⇒ timeUnits should be(None) memoryUnits should be(Some(Memory.KiloBytes)) } @@ -54,9 +54,9 @@ class NeedToScaleSpec extends WordSpec with Matchers { """.stripMargin) config match { - case NeedToScale(timeUnits, memoryUnits) => + case NeedToScale(timeUnits, memoryUnits) ⇒ fail("Should not match") - case _ => + case _ ⇒ } } } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala index dff2c72e..aaf0eabd 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala @@ -32,8 +32,7 @@ import scala.collection.convert.WrapAsScala class MemoryUsageMetrics( instrumentFactory: InstrumentFactory, memoryUsageBeansWithNames: Iterable[MemoryUsageWithMetricName], - bufferPoolBeansWithNames: Iterable[BufferPoolWithMetricName] -) extends GenericEntityRecorder(instrumentFactory) { + bufferPoolBeansWithNames: Iterable[BufferPoolWithMetricName]) extends GenericEntityRecorder(instrumentFactory) { memoryUsageBeansWithNames.foreach { case MemoryUsageWithMetricName(name, beanFun) ⇒ gauge(name + "-used", Memory.Bytes, () ⇒ { @@ -112,6 +111,5 @@ object MemoryUsageMetrics extends JmxSystemMetricRecorderCompanion("jmx-memory") MemoryUsageWithMetricName("non-heap", () ⇒ memoryMXBean.getNonHeapMemoryUsage) :: MemoryUsageWithMetricName("heap", () ⇒ memoryMXBean.getHeapMemoryUsage) :: usagesWithNames, - bufferPoolsWithNames - ) + bufferPoolsWithNames) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala index 314c8450..3d0812cb 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala @@ -10,11 +10,13 @@ class ULimitMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory, logger: val openFiles = histogram("open-files") def update(): Unit = { - openFiles.record(sigar.getProcFd(pid).getTotal) + import SigarSafeRunner._ + + openFiles.record(runSafe(sigar.getProcFd(pid).getTotal, 0L, "open-files", logger)) } } object ULimitMetrics extends SigarMetricRecorderCompanion("ulimit") { def apply(sigar: Sigar, instrumentFactory: InstrumentFactory, logger: LoggingAdapter): ULimitMetrics = new ULimitMetrics(sigar, instrumentFactory, logger) -} \ No newline at end of file +} diff --git a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala index 2facc5a4..a1c41551 100644 --- a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala +++ b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala @@ -151,6 +151,12 @@ class SystemMetricsSpec extends BaseKamonSpec("system-metrics-spec") with Redire processCpuMetrics.histogram("process-cpu").get.numberOfMeasurements should be > 0L } + "record the open files for the application process" in { + val openFilesMetrics = takeSnapshotOf("ulimit", "system-metric") + + openFilesMetrics.histogram("open-files").get.numberOfMeasurements should be > 0L + } + "record Context Switches Global, Voluntary and Non Voluntary metrics when running on Linux" in { if (isLinux) { val contextSwitchesMetrics = takeSnapshotOf("context-switches", "system-metric") -- cgit v1.2.3