aboutsummaryrefslogtreecommitdiff
path: root/kamon-system-metrics/src/main/scala/kamon/metrics
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-06-24 23:35:14 -0300
committerDiego <diegolparra@gmail.com>2014-07-21 17:13:28 -0300
commit5c141733ad39cf2730cf34dc8f3f4a82f0c1b516 (patch)
treeab2830795cacae80aa232e41ed224534572ba678 /kamon-system-metrics/src/main/scala/kamon/metrics
parenta96f6dadd5f77271672215e731b842ce785954f4 (diff)
downloadKamon-5c141733ad39cf2730cf34dc8f3f4a82f0c1b516.tar.gz
Kamon-5c141733ad39cf2730cf34dc8f3f4a82f0c1b516.tar.bz2
Kamon-5c141733ad39cf2730cf34dc8f3f4a82f0c1b516.zip
! kamon-system-metrics: introducing System and JVM metrics module
Diffstat (limited to 'kamon-system-metrics/src/main/scala/kamon/metrics')
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/CPUMetrics.scala84
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/GCMetrics.scala75
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/HeapMetrics.scala82
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/MemoryMetrics.scala96
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/NetworkMetrics.scala94
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala76
6 files changed, 507 insertions, 0 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/CPUMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/CPUMetrics.scala
new file mode 100644
index 00000000..c098d1e5
--- /dev/null
+++ b/kamon-system-metrics/src/main/scala/kamon/metrics/CPUMetrics.scala
@@ -0,0 +1,84 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+package kamon.metrics
+
+import akka.actor.ActorSystem
+import com.typesafe.config.Config
+import kamon.metric.instrument.{ Gauge, Histogram }
+import kamon.metric._
+import kamon.system.SigarExtensionProvider
+import org.hyperic.sigar.SigarProxy
+
+case class CPUMetrics(name: String) extends MetricGroupIdentity {
+ val category = CPUMetrics
+}
+
+object CPUMetrics extends MetricGroupCategory {
+ val name = "cpu"
+
+ case object User extends MetricIdentity { val name = "user" }
+ case object System extends MetricIdentity { val name = "system" }
+ case object Wait extends MetricIdentity { val name = "wait" }
+ case object Idle extends MetricIdentity { val name = "idle" }
+
+ case class CPUMetricRecorder(user: Gauge, system: Gauge, cpuWait: Gauge, idle: Gauge)
+ extends MetricGroupRecorder {
+
+ def collect(context: CollectionContext): MetricGroupSnapshot = {
+ CPUMetricSnapshot(user.collect(context), system.collect(context), cpuWait.collect(context), idle.collect(context))
+ }
+
+ def cleanup: Unit = {}
+ }
+
+ case class CPUMetricSnapshot(user: Histogram.Snapshot, system: Histogram.Snapshot, cpuWait: Histogram.Snapshot, idle: Histogram.Snapshot)
+ extends MetricGroupSnapshot {
+
+ type GroupSnapshotType = CPUMetricSnapshot
+
+ def merge(that: CPUMetricSnapshot, context: CollectionContext): GroupSnapshotType = {
+ CPUMetricSnapshot(user.merge(that.user, context), system.merge(that.system, context), cpuWait.merge(that.cpuWait, context), idle.merge(that.idle, context))
+ }
+
+ lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map(
+ User -> user,
+ System -> system,
+ Wait -> cpuWait,
+ Idle -> idle)
+ }
+
+ val Factory = new MetricGroupFactory with SigarExtensionProvider {
+ def cpu = sigar.getCpu
+
+ type GroupRecorder = CPUMetricRecorder
+
+ def create(config: Config, system: ActorSystem): GroupRecorder = {
+ val settings = config.getConfig("precision.system.cpu")
+
+ val userConfig = settings.getConfig("user")
+ val systemConfig = settings.getConfig("system")
+ val cpuWaitConfig = settings.getConfig("wait")
+ val idleConfig = settings.getConfig("idle")
+
+ new CPUMetricRecorder(
+ Gauge.fromConfig(userConfig, system)(() ⇒ cpu.getUser),
+ Gauge.fromConfig(systemConfig, system)(() ⇒ cpu.getSys),
+ Gauge.fromConfig(cpuWaitConfig, system)(() ⇒ cpu.getWait),
+ Gauge.fromConfig(idleConfig, system)(() ⇒ cpu.getIdle))
+ }
+ }
+}
+
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/GCMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/GCMetrics.scala
new file mode 100644
index 00000000..b5da600e
--- /dev/null
+++ b/kamon-system-metrics/src/main/scala/kamon/metrics/GCMetrics.scala
@@ -0,0 +1,75 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+package kamon.metrics
+
+import java.lang.management.GarbageCollectorMXBean
+
+import akka.actor.ActorSystem
+import com.typesafe.config.Config
+import kamon.metric._
+import kamon.metric.instrument.{ Gauge, Histogram }
+
+case class GCMetrics(name: String) extends MetricGroupIdentity {
+ val category = GCMetrics
+}
+
+object GCMetrics extends MetricGroupCategory {
+ val name = "gc"
+
+ case object CollectionCount extends MetricIdentity { val name = "collection-count" }
+ case object CollectionTime extends MetricIdentity { val name = "collection-time" }
+
+ case class GCMetricRecorder(count: Gauge, time: Gauge)
+ extends MetricGroupRecorder {
+
+ def collect(context: CollectionContext): MetricGroupSnapshot = {
+ GCMetricSnapshot(count.collect(context), time.collect(context))
+ }
+
+ def cleanup: Unit = {}
+ }
+
+ case class GCMetricSnapshot(count: Histogram.Snapshot, time: Histogram.Snapshot)
+ extends MetricGroupSnapshot {
+
+ type GroupSnapshotType = GCMetricSnapshot
+
+ def merge(that: GroupSnapshotType, context: CollectionContext): GroupSnapshotType = {
+ GCMetricSnapshot(count.merge(that.count, context), time.merge(that.time, context))
+ }
+
+ lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map(
+ CollectionCount -> count,
+ CollectionTime -> time)
+ }
+
+ def Factory(gc: GarbageCollectorMXBean) = new MetricGroupFactory {
+
+ type GroupRecorder = GCMetricRecorder
+
+ def create(config: Config, system: ActorSystem): GroupRecorder = {
+ val settings = config.getConfig("precision.jvm.gc")
+
+ val countConfig = settings.getConfig("count")
+ val timeConfig = settings.getConfig("time")
+
+ new GCMetricRecorder(
+ Gauge.fromConfig(countConfig, system)(() ⇒ gc.getCollectionCount),
+ Gauge.fromConfig(timeConfig, system, Scale.Milli)(() ⇒ gc.getCollectionTime))
+ }
+ }
+}
+
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/HeapMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/HeapMetrics.scala
new file mode 100644
index 00000000..09174f47
--- /dev/null
+++ b/kamon-system-metrics/src/main/scala/kamon/metrics/HeapMetrics.scala
@@ -0,0 +1,82 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+package kamon.metrics
+
+import java.lang.management.ManagementFactory
+
+import akka.actor.ActorSystem
+import com.typesafe.config.Config
+import kamon.metric._
+import kamon.metric.instrument.{ Gauge, Histogram }
+
+case class HeapMetrics(name: String) extends MetricGroupIdentity {
+ val category = HeapMetrics
+}
+
+object HeapMetrics extends MetricGroupCategory {
+ val name = "heap"
+
+ case object Used extends MetricIdentity { val name = "used-heap" }
+ case object Max extends MetricIdentity { val name = "max-heap" }
+ case object Committed extends MetricIdentity { val name = "committed-heap" }
+
+ case class HeapMetricRecorder(used: Gauge, max: Gauge, committed: Gauge)
+ extends MetricGroupRecorder {
+
+ def collect(context: CollectionContext): MetricGroupSnapshot = {
+ HeapMetricSnapshot(used.collect(context), max.collect(context), committed.collect(context))
+ }
+
+ def cleanup: Unit = {}
+ }
+
+ case class HeapMetricSnapshot(used: Histogram.Snapshot, max: Histogram.Snapshot, committed: Histogram.Snapshot)
+ extends MetricGroupSnapshot {
+
+ type GroupSnapshotType = HeapMetricSnapshot
+
+ def merge(that: GroupSnapshotType, context: CollectionContext): GroupSnapshotType = {
+ HeapMetricSnapshot(used.merge(that.used, context), max.merge(that.max, context), committed.merge(that.committed, context))
+ }
+
+ lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map(
+ Used -> used,
+ Max -> max,
+ Committed -> committed)
+ }
+
+ val Factory = new MetricGroupFactory {
+
+ val memory = ManagementFactory.getMemoryMXBean
+ def heap = memory.getHeapMemoryUsage
+
+ type GroupRecorder = HeapMetricRecorder
+
+ def create(config: Config, system: ActorSystem): GroupRecorder = {
+ val settings = config.getConfig("precision.jvm.heap")
+
+ val usedHeapConfig = settings.getConfig("used")
+ val maxHeapConfig = settings.getConfig("max")
+ val committedHeapConfig = settings.getConfig("committed")
+
+ new HeapMetricRecorder(
+ Gauge.fromConfig(usedHeapConfig, system)(() ⇒ heap.getUsed),
+ Gauge.fromConfig(maxHeapConfig, system)(() ⇒ heap.getMax),
+ Gauge.fromConfig(committedHeapConfig, system)(() ⇒ heap.getCommitted))
+ }
+ }
+}
+
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/MemoryMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/MemoryMetrics.scala
new file mode 100644
index 00000000..4f6cb1cd
--- /dev/null
+++ b/kamon-system-metrics/src/main/scala/kamon/metrics/MemoryMetrics.scala
@@ -0,0 +1,96 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+package kamon.metrics
+
+import akka.actor.ActorSystem
+import com.typesafe.config.Config
+import kamon.metric._
+import kamon.metric.instrument.Gauge.CurrentValueCollector
+import kamon.metric.instrument.{ Gauge, Histogram }
+import kamon.system.SigarExtensionProvider
+import org.hyperic.sigar.Mem
+
+case class MemoryMetrics(name: String) extends MetricGroupIdentity {
+ val category = MemoryMetrics
+}
+
+object MemoryMetrics extends MetricGroupCategory {
+ val name = "memory"
+
+ case object Used extends MetricIdentity { val name = "used" }
+ case object Free extends MetricIdentity { val name = "free" }
+ case object Buffer extends MetricIdentity { val name = "buffer" }
+ case object Cache extends MetricIdentity { val name = "cache" }
+ case object SwapUsed extends MetricIdentity { val name = "swap-used" }
+ case object SwapFree extends MetricIdentity { val name = "swap-free" }
+
+ case class MemoryMetricRecorder(used: Gauge, free: Gauge, buffer: Gauge, cache: Gauge, swapUsed: Gauge, swapFree: Gauge)
+ extends MetricGroupRecorder {
+
+ def collect(context: CollectionContext): MetricGroupSnapshot = {
+ MemoryMetricSnapshot(used.collect(context), free.collect(context), buffer.collect(context), cache.collect(context), swapUsed.collect(context), swapFree.collect(context))
+ }
+
+ def cleanup: Unit = {}
+ }
+
+ case class MemoryMetricSnapshot(used: Histogram.Snapshot, free: Histogram.Snapshot, buffer: Histogram.Snapshot, cache: Histogram.Snapshot, swapUsed: Histogram.Snapshot, swapFree: Histogram.Snapshot)
+ extends MetricGroupSnapshot {
+
+ type GroupSnapshotType = MemoryMetricSnapshot
+
+ def merge(that: GroupSnapshotType, context: CollectionContext): GroupSnapshotType = {
+ MemoryMetricSnapshot(used.merge(that.used, context), free.merge(that.free, context), buffer.merge(that.buffer, context), cache.merge(that.cache, context), swapUsed.merge(that.swapUsed, context), swapFree.merge(that.swapFree, context))
+ }
+
+ lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map(
+ Used -> used,
+ Free -> free,
+ Buffer -> buffer,
+ Cache -> cache,
+ SwapUsed -> swapUsed,
+ SwapFree -> swapFree)
+ }
+
+ val Factory = new MetricGroupFactory with SigarExtensionProvider {
+ def mem = sigar.getMem
+ def swap = sigar.getSwap
+
+ type GroupRecorder = MemoryMetricRecorder
+
+ def create(config: Config, system: ActorSystem): GroupRecorder = {
+ val settings = config.getConfig("precision.system.memory")
+
+ val usedConfig = settings.getConfig("used")
+ val freeConfig = settings.getConfig("free")
+ val bufferConfig = settings.getConfig("buffer")
+ val cacheConfig = settings.getConfig("cache")
+ val swapUsedConfig = settings.getConfig("swap-used")
+ val swapFreeConfig = settings.getConfig("swap-free")
+
+ new MemoryMetricRecorder(
+ Gauge.fromConfig(usedConfig, system)(() ⇒ mem.getUsed),
+ Gauge.fromConfig(freeConfig, system)(() ⇒ mem.getFree),
+ Gauge.fromConfig(bufferConfig, system)(() ⇒ swap.getUsed),
+ Gauge.fromConfig(cacheConfig, system)(() ⇒ swap.getFree),
+ Gauge.fromConfig(swapUsedConfig, system)(collectBuffer(mem)),
+ Gauge.fromConfig(swapFreeConfig, system)(collectCache(mem)))
+ }
+
+ private def collectBuffer(mem: Mem) = () ⇒ if (mem.getUsed() != mem.getActualUsed()) mem.getActualUsed() else 0L
+ private def collectCache(mem: Mem) = () ⇒ if (mem.getFree() != mem.getActualFree()) mem.getActualFree() else 0L
+ }
+} \ No newline at end of file
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/NetworkMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/NetworkMetrics.scala
new file mode 100644
index 00000000..62fc3fcd
--- /dev/null
+++ b/kamon-system-metrics/src/main/scala/kamon/metrics/NetworkMetrics.scala
@@ -0,0 +1,94 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+package kamon.metrics
+
+import akka.actor.ActorSystem
+import com.typesafe.config.Config
+import kamon.metric._
+import kamon.metric.instrument.Gauge.CurrentValueCollector
+import kamon.metric.instrument.{ Gauge, Histogram }
+import kamon.system.SigarExtensionProvider
+import org.hyperic.sigar.{ NetInterfaceStat, SigarProxy }
+
+case class NetworkMetrics(name: String) extends MetricGroupIdentity {
+ val category = NetworkMetrics
+}
+
+object NetworkMetrics extends MetricGroupCategory {
+ val name = "network"
+
+ case object RxBytes extends MetricIdentity { val name = "rx-bytes" }
+ case object TxBytes extends MetricIdentity { val name = "tx-bytes" }
+ case object RxErrors extends MetricIdentity { val name = "rx-errors" }
+ case object TxErrors extends MetricIdentity { val name = "tx-errors" }
+
+ case class NetworkMetricRecorder(rxBytes: Gauge, txBytes: Gauge, rxErrors: Gauge, txErrors: Gauge)
+ extends MetricGroupRecorder {
+
+ def collect(context: CollectionContext): MetricGroupSnapshot = {
+ NetworkMetricSnapshot(rxBytes.collect(context), txBytes.collect(context), rxErrors.collect(context), txErrors.collect(context))
+ }
+
+ def cleanup: Unit = {}
+ }
+
+ case class NetworkMetricSnapshot(rxBytes: Histogram.Snapshot, txBytes: Histogram.Snapshot, rxErrors: Histogram.Snapshot, txErrors: Histogram.Snapshot)
+ extends MetricGroupSnapshot {
+
+ type GroupSnapshotType = NetworkMetricSnapshot
+
+ def merge(that: GroupSnapshotType, context: CollectionContext): GroupSnapshotType = {
+ NetworkMetricSnapshot(rxBytes.merge(that.rxBytes, context), txBytes.merge(that.txBytes, context), rxErrors.merge(that.rxErrors, context), txErrors.merge(that.txErrors, context))
+ }
+
+ val metrics: Map[MetricIdentity, MetricSnapshot] = Map(
+ RxBytes -> rxBytes,
+ TxBytes -> txBytes,
+ RxErrors -> rxErrors,
+ TxErrors -> txErrors)
+ }
+
+ val Factory = new MetricGroupFactory with SigarExtensionProvider {
+
+ val interfaces: Set[String] = sigar.getNetInterfaceList.toSet
+
+ type GroupRecorder = NetworkMetricRecorder
+
+ def create(config: Config, system: ActorSystem): GroupRecorder = {
+ val settings = config.getConfig("precision.system.network")
+
+ val rxBytesConfig = settings.getConfig("rx-bytes")
+ val txBytesConfig = settings.getConfig("tx-bytes")
+ val rxErrorsConfig = settings.getConfig("rx-errors")
+ val txErrorsConfig = settings.getConfig("tx-errors")
+
+ new NetworkMetricRecorder(
+ Gauge.fromConfig(rxBytesConfig, system)(collect(sigar, interfaces)(net ⇒ net.getRxBytes)),
+ Gauge.fromConfig(txBytesConfig, system)(collect(sigar, interfaces)(net ⇒ net.getTxBytes)),
+ Gauge.fromConfig(rxErrorsConfig, system)(collect(sigar, interfaces)(net ⇒ net.getRxErrors)),
+ Gauge.fromConfig(txErrorsConfig, system)(collect(sigar, interfaces)(net ⇒ net.getTxErrors)))
+ }
+
+ private def collect(sigar: SigarProxy, interfaces: Set[String])(block: NetInterfaceStat ⇒ Long) = () ⇒ {
+ interfaces.foldLeft(0L) { (totalBytes, interface) ⇒
+ {
+ val net = sigar.getNetInterfaceStat(interface)
+ totalBytes + block(net)
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala
new file mode 100644
index 00000000..356504b7
--- /dev/null
+++ b/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala
@@ -0,0 +1,76 @@
+/*
+ * =========================================================================================
+ * Copyright © 2013-2014 the kamon project <http://kamon.io/>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions
+ * and limitations under the License.
+ * =========================================================================================
+ */
+package kamon.metrics
+
+import akka.actor.ActorSystem
+import com.typesafe.config.Config
+import kamon.metric.instrument.{ Gauge, Histogram }
+import kamon.metric._
+import kamon.system.SigarExtensionProvider
+
+case class ProcessCPUMetrics(name: String) extends MetricGroupIdentity {
+ val category = ProcessCPUMetrics
+}
+
+object ProcessCPUMetrics extends MetricGroupCategory {
+ val name = "proc-cpu"
+
+ case object User extends MetricIdentity { val name = "user" }
+ case object System extends MetricIdentity { val name = "system" }
+
+ case class ProcessCPUMetricsRecorder(user: Gauge, system: Gauge)
+ extends MetricGroupRecorder {
+
+ def collect(context: CollectionContext): MetricGroupSnapshot = {
+ ProcessCPUMetricsSnapshot(user.collect(context), system.collect(context))
+ }
+
+ def cleanup: Unit = {}
+ }
+
+ case class ProcessCPUMetricsSnapshot(user: Histogram.Snapshot, system: Histogram.Snapshot)
+ extends MetricGroupSnapshot {
+
+ type GroupSnapshotType = ProcessCPUMetricsSnapshot
+
+ def merge(that: ProcessCPUMetricsSnapshot, context: CollectionContext): GroupSnapshotType = {
+ ProcessCPUMetricsSnapshot(user.merge(that.user, context), system.merge(that.system, context))
+ }
+
+ lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map(
+ User -> user,
+ System -> system)
+ }
+
+ val Factory = new MetricGroupFactory with SigarExtensionProvider {
+ def pid = sigar.getPid
+ def cpu = sigar.getProcCpu(pid)
+
+ type GroupRecorder = ProcessCPUMetricsRecorder
+
+ def create(config: Config, system: ActorSystem): GroupRecorder = {
+ val settings = config.getConfig("precision.system.process-cpu")
+
+ val userConfig = settings.getConfig("user")
+ val systemConfig = settings.getConfig("system")
+
+ new ProcessCPUMetricsRecorder(
+ Gauge.fromConfig(userConfig, system)(() ⇒ cpu.getUser),
+ Gauge.fromConfig(systemConfig, system)(() ⇒ cpu.getSys))
+ }
+ }
+}
+