aboutsummaryrefslogtreecommitdiff
path: root/kamon-system-metrics/src/test/scala/kamon/metrics
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2015-01-12 01:45:27 +0100
committerIvan Topolnjak <ivantopo@gmail.com>2015-01-24 23:19:01 +0100
commit01a34f67ff75419c440f2e69c0a0db888a670a34 (patch)
tree9c4dee4e9c13c26937356950f9e4927c3f9dfb7d /kamon-system-metrics/src/test/scala/kamon/metrics
parent4a47e92d23af371f1d50b40af6cbe00a5ffc0105 (diff)
downloadKamon-01a34f67ff75419c440f2e69c0a0db888a670a34.tar.gz
Kamon-01a34f67ff75419c440f2e69c0a0db888a670a34.tar.bz2
Kamon-01a34f67ff75419c440f2e69c0a0db888a670a34.zip
! all: improve the metric recorders infrastructure
Diffstat (limited to 'kamon-system-metrics/src/test/scala/kamon/metrics')
-rw-r--r--kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala450
1 files changed, 92 insertions, 358 deletions
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 c9530160..4d633952 100644
--- a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala
+++ b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala
@@ -15,406 +15,140 @@
package kamon.metric
-import akka.actor.ActorSystem
-import akka.testkit.{ TestKitBase, TestProbe }
-import com.typesafe.config.ConfigFactory
-import kamon.Kamon
-import kamon.metric.Subscriptions.TickMetricSnapshot
-import kamon.metrics.CPUMetrics.CPUMetricSnapshot
-import kamon.metrics.ClassLoadingMetrics.ClassLoadingMetricSnapshot
-import kamon.metrics.ContextSwitchesMetrics.ContextSwitchesMetricsSnapshot
-import kamon.metrics.DiskMetrics.DiskMetricsSnapshot
-import kamon.metrics.GCMetrics.GCMetricSnapshot
-import kamon.metrics.HeapMetrics.HeapMetricSnapshot
-import kamon.metrics.LoadAverageMetrics.LoadAverageMetricsSnapshot
-import kamon.metrics.MemoryMetrics.MemoryMetricSnapshot
-import kamon.metrics.NetworkMetrics.NetworkMetricSnapshot
-import kamon.metrics.NonHeapMetrics.NonHeapMetricSnapshot
-import kamon.metrics.ProcessCPUMetrics.ProcessCPUMetricsSnapshot
-import kamon.metrics.ThreadMetrics.ThreadMetricSnapshot
-import kamon.metrics._
-import kamon.system.SystemMetricsExtension
-import org.scalatest.{ Matchers, WordSpecLike }
-
-import scala.concurrent.duration._
-
-class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers with RedirectLogging {
- implicit lazy val system: ActorSystem = ActorSystem("system-metrics-spec", ConfigFactory.parseString(
- """
- |akka {
- | extensions = ["kamon.system.SystemMetrics"]
- |}
- |
- |kamon.metrics {
- | disable-aspectj-weaver-missing-error = true
- | tick-interval = 1 second
- |}
- """.stripMargin))
-
- "the Kamon CPU Metrics" should {
- "record user, system, wait, idle, stolen metrics" in new CPUMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val CPUMetrics = expectCPUMetrics(metricsListener, 3 seconds)
- CPUMetrics.user.max should be >= 0L
- CPUMetrics.system.max should be >= 0L
- CPUMetrics.cpuWait.max should be >= 0L
- CPUMetrics.idle.max should be >= 0L
- CPUMetrics.stolen.max should be >= 0L
- }
- }
- "the Kamon GC Metrics" should {
- "record count, time metrics" in new GCMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val GCMetrics = expectGCMetrics(metricsListener, 3 seconds)
- GCMetrics.count.max should be >= 0L
- GCMetrics.time.max should be >= 0L
- }
- }
-
- "the Kamon Heap Metrics" should {
- "record used, max, commited metrics" in new HeapMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val HeapMetrics = expectHeapMetrics(metricsListener, 3 seconds)
- HeapMetrics.used.max should be >= 0L
- HeapMetrics.max.max should be >= 0L
- HeapMetrics.committed.max should be >= 0L
- }
- }
-
- "the Kamon Non-Heap Metrics" should {
- "record used, max, commited metrics" in new NonHeapMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val NonHeapMetrics = expectNonHeapMetrics(metricsListener, 3 seconds)
- NonHeapMetrics.used.max should be >= 0L
- NonHeapMetrics.max.max should be >= 0L
- NonHeapMetrics.committed.max should be >= 0L
- }
- }
-
- "the Kamon Thread Metrics" should {
- "record daemon, count, peak metrics" in new ThreadMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val ThreadMetrics = expectThreadMetrics(metricsListener, 3 seconds)
- ThreadMetrics.daemon.max should be >= 0L
- ThreadMetrics.count.max should be >= 0L
- ThreadMetrics.peak.max should be >= 0L
- }
- }
-
- "the Kamon ClassLoading Metrics" should {
- "record loaded, unloaded, current metrics" in new ClassLoadingMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
+import java.lang.management.ManagementFactory
- val ClassLoadingMetrics = expectClassLoadingMetrics(metricsListener, 3 seconds)
- ClassLoadingMetrics.loaded.max should be >= 0L
- ClassLoadingMetrics.unloaded.max should be >= 0L
- ClassLoadingMetrics.current.max should be >= 0L
- }
- }
-
- "the Kamon Disk Metrics" should {
- "record reads, writes, queue, service time metrics" in new DiskMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val DiskMetrics = expectDiskMetrics(metricsListener, 3 seconds)
- DiskMetrics.reads.max should be >= 0L
- DiskMetrics.writes.max should be >= 0L
- DiskMetrics.queue.max should be >= 0L
- DiskMetrics.serviceTime.max should be >= 0L
- }
- }
-
- "the Kamon Load Average Metrics" should {
- "record 1 minute, 5 minutes and 15 minutes metrics" in new LoadAverageMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val LoadAverageMetrics = expectLoadAverageMetrics(metricsListener, 3 seconds)
- LoadAverageMetrics.one.max should be >= 0L
- LoadAverageMetrics.five.max should be >= 0L
- LoadAverageMetrics.fifteen.max should be >= 0L
- }
- }
+import com.typesafe.config.ConfigFactory
+import kamon.system.jmx.GarbageCollectionMetrics
+import kamon.testkit.BaseKamonSpec
+import scala.collection.JavaConverters._
- "the Kamon Memory Metrics" should {
- "record used, free, buffer, cache, swap used, swap free metrics" in new MemoryMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val MemoryMetrics = expectMemoryMetrics(metricsListener, 3 seconds)
- MemoryMetrics.used.max should be >= 0L
- MemoryMetrics.free.max should be >= 0L
- MemoryMetrics.buffer.max should be >= 0L
- MemoryMetrics.cache.max should be >= 0L
- MemoryMetrics.swapUsed.max should be >= 0L
- MemoryMetrics.swapFree.max should be >= 0L
- }
- }
+class SystemMetricsSpec extends BaseKamonSpec("system-metrics-spec") with RedirectLogging {
- "the Kamon Network Metrics" should {
- "record rxBytes, txBytes, rxErrors, txErrors, rxDropped, txDropped metrics" in new NetworkMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
-
- val NetworkMetrics = expectNetworkMetrics(metricsListener, 3 seconds)
- NetworkMetrics.rxBytes.max should be >= 0L
- NetworkMetrics.txBytes.max should be >= 0L
- NetworkMetrics.rxErrors.max should be >= 0L
- NetworkMetrics.txErrors.max should be >= 0L
- NetworkMetrics.rxDropped.max should be >= 0L
- NetworkMetrics.txDropped.max should be >= 0L
- }
- }
-
- "the Kamon Process CPU Metrics" should {
- "record Cpu Percent, Total Process Time metrics" in new ProcessCPUMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
+ override lazy val config =
+ ConfigFactory.parseString(
+ """
+ |kamon.metric {
+ | tick-interval = 1 hour
+ |}
+ |
+ |akka {
+ | extensions = ["kamon.system.SystemMetrics"]
+ |}
+ """.stripMargin)
- val ProcessCPUMetrics = expectProcessCPUMetrics(metricsListener, 3 seconds)
- ProcessCPUMetrics.cpuPercent.max should be >= 0L
- ProcessCPUMetrics.totalProcessTime.max should be >= 0L
- }
- }
+ override protected def beforeAll(): Unit =
+ Thread.sleep(2000) // Give some room to the recorders to store some values.
- "the Kamon ContextSwitches Metrics" should {
- "record Context Switches Global, Voluntary and Non Voluntary metrics" in new ContextSwitchesMetricsListenerFixture {
- val metricsListener = subscribeToMetrics()
+ "the Kamon System Metrics module" should {
+ "record user, system, wait, idle and stolen CPU metrics" in {
+ val cpuMetrics = takeSnapshotOf("cpu", "system-metric")
- val ContextSwitchesMetrics = expectContextSwitchesMetrics(metricsListener, 3 seconds)
- ContextSwitchesMetrics.perProcessVoluntary.max should be >= 0L
- ContextSwitchesMetrics.perProcessNonVoluntary.max should be >= 0L
- ContextSwitchesMetrics.global.max should be >= 0L
+ cpuMetrics.histogram("cpu-user").get.numberOfMeasurements should be > 0L
+ cpuMetrics.histogram("cpu-system").get.numberOfMeasurements should be > 0L
+ cpuMetrics.histogram("cpu-wait").get.numberOfMeasurements should be > 0L
+ cpuMetrics.histogram("cpu-idle").get.numberOfMeasurements should be > 0L
+ cpuMetrics.histogram("cpu-stolen").get.numberOfMeasurements should be > 0L
}
- }
- def expectCPUMetrics(listener: TestProbe, waitTime: FiniteDuration): CPUMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
- }
- val cpuMetricsOption = tickSnapshot.metrics.get(CPUMetrics(SystemMetricsExtension.CPU))
- cpuMetricsOption should not be empty
- cpuMetricsOption.get.asInstanceOf[CPUMetricSnapshot]
- }
+ "record count and time garbage collection metrics" in {
+ val availableGarbageCollectors = ManagementFactory.getGarbageCollectorMXBeans.asScala.filter(_.isValid)
- trait CPUMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(CPUMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
+ for (collectorName ← availableGarbageCollectors) {
+ val sanitizedName = GarbageCollectionMetrics.sanitizeCollectorName(collectorName.getName)
+ val collectorMetrics = takeSnapshotOf(s"$sanitizedName-garbage-collector", "system-metric")
- def expectGCMetrics(listener: TestProbe, waitTime: FiniteDuration): GCMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
+ collectorMetrics.gauge("garbage-collection-count").get.numberOfMeasurements should be > 0L
+ collectorMetrics.gauge("garbage-collection-time").get.numberOfMeasurements should be > 0L
+ }
}
- val gcMetricsOption = tickSnapshot.metrics.get(GCMetrics(SystemMetricsExtension.garbageCollectors(0).getName.replaceAll("""[^\w]""", "-")))
- gcMetricsOption should not be empty
- gcMetricsOption.get.asInstanceOf[GCMetricSnapshot]
- }
+ "record used, max and committed heap metrics" in {
+ val heapMetrics = takeSnapshotOf("heap-memory", "system-metric")
- trait GCMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(GCMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
+ heapMetrics.gauge("heap-used").get.numberOfMeasurements should be > 0L
+ heapMetrics.gauge("heap-max").get.numberOfMeasurements should be > 0L
+ heapMetrics.gauge("heap-committed").get.numberOfMeasurements should be > 0L
}
- }
- def expectHeapMetrics(listener: TestProbe, waitTime: FiniteDuration): HeapMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
- }
- val heapMetricsOption = tickSnapshot.metrics.get(HeapMetrics(SystemMetricsExtension.Heap))
- heapMetricsOption should not be empty
- heapMetricsOption.get.asInstanceOf[HeapMetricSnapshot]
- }
+ "record used, max and committed non-heap metrics" in {
+ val nonHeapMetrics = takeSnapshotOf("non-heap-memory", "system-metric")
- trait HeapMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(HeapMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
+ nonHeapMetrics.gauge("non-heap-used").get.numberOfMeasurements should be > 0L
+ nonHeapMetrics.gauge("non-heap-max").get.numberOfMeasurements should be > 0L
+ nonHeapMetrics.gauge("non-heap-committed").get.numberOfMeasurements should be > 0L
}
- }
- trait NonHeapMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(NonHeapMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
+ "record daemon, count and peak jvm threads metrics" in {
+ val threadsMetrics = takeSnapshotOf("threads", "system-metric")
- def expectNonHeapMetrics(listener: TestProbe, waitTime: FiniteDuration): NonHeapMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
+ threadsMetrics.gauge("daemon-thread-count").get.numberOfMeasurements should be > 0L
+ threadsMetrics.gauge("peak-thread-count").get.numberOfMeasurements should be > 0L
+ threadsMetrics.gauge("thread-count").get.numberOfMeasurements should be > 0L
}
- val nonHeapMetricsOption = tickSnapshot.metrics.get(NonHeapMetrics(SystemMetricsExtension.NonHeap))
- nonHeapMetricsOption should not be empty
- nonHeapMetricsOption.get.asInstanceOf[NonHeapMetricSnapshot]
- }
- trait ThreadMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(ThreadMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
+ "record loaded, unloaded and current class loading metrics" in {
+ val classLoadingMetrics = takeSnapshotOf("class-loading", "system-metric")
- def expectThreadMetrics(listener: TestProbe, waitTime: FiniteDuration): ThreadMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
+ classLoadingMetrics.gauge("classes-loaded").get.numberOfMeasurements should be > 0L
+ classLoadingMetrics.gauge("classes-unloaded").get.numberOfMeasurements should be > 0L
+ classLoadingMetrics.gauge("classes-currently-loaded").get.numberOfMeasurements should be > 0L
}
- val threadMetricsOption = tickSnapshot.metrics.get(ThreadMetrics(SystemMetricsExtension.Threads))
- threadMetricsOption should not be empty
- threadMetricsOption.get.asInstanceOf[ThreadMetricSnapshot]
- }
- trait ClassLoadingMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(ClassLoadingMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
+ "record reads, writes, queue time and service time file system metrics" in {
+ val fileSystemMetrics = takeSnapshotOf("file-system", "system-metric")
- def expectClassLoadingMetrics(listener: TestProbe, waitTime: FiniteDuration): ClassLoadingMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
+ fileSystemMetrics.histogram("file-system-reads").get.numberOfMeasurements should be > 0L
+ fileSystemMetrics.histogram("file-system-writes").get.numberOfMeasurements should be > 0L
}
- val classLoadingMetricsOption = tickSnapshot.metrics.get(ClassLoadingMetrics(SystemMetricsExtension.Classes))
- classLoadingMetricsOption should not be empty
- classLoadingMetricsOption.get.asInstanceOf[ClassLoadingMetricSnapshot]
- }
- trait DiskMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(DiskMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
+ "record 1 minute, 5 minutes and 15 minutes metrics load average metrics" in {
+ val loadAverage = takeSnapshotOf("load-average", "system-metric")
- def expectDiskMetrics(listener: TestProbe, waitTime: FiniteDuration): DiskMetricsSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
+ loadAverage.histogram("one-minute").get.numberOfMeasurements should be > 0L
+ loadAverage.histogram("five-minutes").get.numberOfMeasurements should be > 0L
+ loadAverage.histogram("fifteen-minutes").get.numberOfMeasurements should be > 0L
}
- val diskMetricsOption = tickSnapshot.metrics.get(DiskMetrics(SystemMetricsExtension.Disk))
- diskMetricsOption should not be empty
- diskMetricsOption.get.asInstanceOf[DiskMetricsSnapshot]
- }
- trait LoadAverageMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(LoadAverageMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
+ "record used, free, swap used, swap free system memory metrics" in {
+ val memoryMetrics = takeSnapshotOf("memory", "system-metric")
- def expectLoadAverageMetrics(listener: TestProbe, waitTime: FiniteDuration): LoadAverageMetricsSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
+ memoryMetrics.histogram("memory-used").get.numberOfMeasurements should be > 0L
+ memoryMetrics.histogram("memory-free").get.numberOfMeasurements should be > 0L
+ memoryMetrics.histogram("swap-used").get.numberOfMeasurements should be > 0L
+ memoryMetrics.histogram("swap-free").get.numberOfMeasurements should be > 0L
}
- val loadAverageMetricsOption = tickSnapshot.metrics.get(LoadAverageMetrics(SystemMetricsExtension.LoadAverage))
- loadAverageMetricsOption should not be empty
- loadAverageMetricsOption.get.asInstanceOf[LoadAverageMetricsSnapshot]
- }
- def expectMemoryMetrics(listener: TestProbe, waitTime: FiniteDuration): MemoryMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
- }
- val memoryMetricsOption = tickSnapshot.metrics.get(MemoryMetrics(SystemMetricsExtension.Memory))
- memoryMetricsOption should not be empty
- memoryMetricsOption.get.asInstanceOf[MemoryMetricSnapshot]
- }
+ "record rxBytes, txBytes, rxErrors, txErrors, rxDropped, txDropped network metrics" in {
+ val networkMetrics = takeSnapshotOf("network", "system-metric")
- trait MemoryMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(MemoryMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
+ networkMetrics.histogram("tx-bytes").get.numberOfMeasurements should be > 0L
+ networkMetrics.histogram("rx-bytes").get.numberOfMeasurements should be > 0L
+ networkMetrics.histogram("tx-errors").get.numberOfMeasurements should be > 0L
+ networkMetrics.histogram("rx-errors").get.numberOfMeasurements should be > 0L
+ networkMetrics.histogram("tx-dropped").get.numberOfMeasurements should be > 0L
+ networkMetrics.histogram("rx-dropped").get.numberOfMeasurements should be > 0L
}
- }
- def expectNetworkMetrics(listener: TestProbe, waitTime: FiniteDuration): NetworkMetricSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
- }
- val networkMetricsOption = tickSnapshot.metrics.get(NetworkMetrics(SystemMetricsExtension.Network))
- networkMetricsOption should not be empty
- networkMetricsOption.get.asInstanceOf[NetworkMetricSnapshot]
- }
+ "record system and user CPU percentage for the application process" in {
+ val processCpuMetrics = takeSnapshotOf("process-cpu", "system-metric")
- trait NetworkMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(NetworkMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
+ processCpuMetrics.histogram("process-user-cpu").get.numberOfMeasurements should be > 0L
+ processCpuMetrics.histogram("process-system-cpu").get.numberOfMeasurements should be > 0L
+ processCpuMetrics.histogram("process-cpu").get.numberOfMeasurements should be > 0L
}
- }
- def expectProcessCPUMetrics(listener: TestProbe, waitTime: FiniteDuration): ProcessCPUMetricsSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
- }
- val processCPUMetricsOption = tickSnapshot.metrics.get(ProcessCPUMetrics(SystemMetricsExtension.ProcessCPU))
- processCPUMetricsOption should not be empty
- processCPUMetricsOption.get.asInstanceOf[ProcessCPUMetricsSnapshot]
- }
+ "record Context Switches Global, Voluntary and Non Voluntary metrics when running on Linux" in {
+ if (isLinux) {
+ val contextSwitchesMetrics = takeSnapshotOf("context-switches", "system-metric")
- trait ProcessCPUMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(ProcessCPUMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
+ contextSwitchesMetrics.histogram("context-switches-process-voluntary").get.numberOfMeasurements should be > 0L
+ contextSwitchesMetrics.histogram("context-switches-process-non-voluntary").get.numberOfMeasurements should be > 0L
+ contextSwitchesMetrics.histogram("context-switches-global").get.numberOfMeasurements should be > 0L
+ }
}
}
- def expectContextSwitchesMetrics(listener: TestProbe, waitTime: FiniteDuration): ContextSwitchesMetricsSnapshot = {
- val tickSnapshot = within(waitTime) {
- listener.expectMsgType[TickMetricSnapshot]
- }
- val contextSwitchesMetricsOption = tickSnapshot.metrics.get(ContextSwitchesMetrics(SystemMetricsExtension.ContextSwitches))
- contextSwitchesMetricsOption should not be empty
- contextSwitchesMetricsOption.get.asInstanceOf[ContextSwitchesMetricsSnapshot]
- }
+ def isLinux: Boolean =
+ System.getProperty("os.name").indexOf("Linux") != -1
- trait ContextSwitchesMetricsListenerFixture {
- def subscribeToMetrics(): TestProbe = {
- val metricsListener = TestProbe()
- Kamon(Metrics).subscribe(ContextSwitchesMetrics, "*", metricsListener.ref, permanently = true)
- // Wait for one empty snapshot before proceeding to the test.
- metricsListener.expectMsgType[TickMetricSnapshot]
- metricsListener
- }
- }
}