diff options
Diffstat (limited to 'kamon-system-metrics/src/main')
7 files changed, 39 insertions, 38 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala index 0a5f6494..4645f4cd 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/CpuMetrics.scala @@ -4,14 +4,14 @@ import kamon.metric.GenericEntityRecorder import kamon.metric.instrument.InstrumentFactory import org.hyperic.sigar.Sigar -class CpuMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class CpuMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val user = histogram("cpu-user") val system = histogram("cpu-system") val Wait = histogram("cpu-wait") val idle = histogram("cpu-idle") val stolen = histogram("cpu-stolen") - def update(sigar: Sigar): Unit = { + def update(): Unit = { val cpuPerc = sigar.getCpuPerc user.record((cpuPerc.getUser * 100L).toLong) @@ -24,6 +24,6 @@ class CpuMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityReco object CpuMetrics extends SigarMetricRecorderCompanion("cpu") { - def apply(instrumentFactory: InstrumentFactory): CpuMetrics = - new CpuMetrics(instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): CpuMetrics = + new CpuMetrics(sigar, instrumentFactory) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/FileSystemMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/FileSystemMetrics.scala index d34b6415..28e40469 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/FileSystemMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/FileSystemMetrics.scala @@ -5,23 +5,23 @@ import kamon.metric.instrument.{ Memory, InstrumentFactory } import org.hyperic.sigar.{ DiskUsage, FileSystem, Sigar } import scala.util.Try -class FileSystemMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class FileSystemMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val reads = DiffRecordingHistogram(histogram("file-system-reads", Memory.Bytes)) val writes = DiffRecordingHistogram(histogram("file-system-writes", Memory.Bytes)) + val fileSystems = sigar.getFileSystemList.filter(_.getType == FileSystem.TYPE_LOCAL_DISK).map(_.getDevName).toSet + def sumOfAllFileSystems(sigar: Sigar, thunk: DiskUsage ⇒ Long): Long = Try { - val fileSystems = sigar.getFileSystemList.filter(_.getType == FileSystem.TYPE_LOCAL_DISK).map(_.getDevName).toSet fileSystems.map(i ⇒ thunk(sigar.getDiskUsage(i))).fold(0L)(_ + _) - } getOrElse (0L) - def update(sigar: Sigar): Unit = { + def update(): Unit = { reads.record(sumOfAllFileSystems(sigar, _.getReadBytes)) writes.record(sumOfAllFileSystems(sigar, _.getWriteBytes)) } } object FileSystemMetrics extends SigarMetricRecorderCompanion("file-system") { - def apply(instrumentFactory: InstrumentFactory): FileSystemMetrics = - new FileSystemMetrics(instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): FileSystemMetrics = + new FileSystemMetrics(sigar, instrumentFactory) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/LoadAverageMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/LoadAverageMetrics.scala index 3e02cc8f..5696270c 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/LoadAverageMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/LoadAverageMetrics.scala @@ -4,12 +4,12 @@ import kamon.metric.GenericEntityRecorder import kamon.metric.instrument.InstrumentFactory import org.hyperic.sigar.Sigar -class LoadAverageMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class LoadAverageMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val oneMinute = histogram("one-minute") val fiveMinutes = histogram("five-minutes") val fifteenMinutes = histogram("fifteen-minutes") - def update(sigar: Sigar): Unit = { + def update(): Unit = { val loadAverage = sigar.getLoadAverage oneMinute.record(loadAverage(0).toLong) @@ -20,6 +20,6 @@ class LoadAverageMetrics(instrumentFactory: InstrumentFactory) extends GenericEn object LoadAverageMetrics extends SigarMetricRecorderCompanion("load-average") { - def apply(instrumentFactory: InstrumentFactory): LoadAverageMetrics = - new LoadAverageMetrics(instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): LoadAverageMetrics = + new LoadAverageMetrics(sigar, instrumentFactory) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/MemoryMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/MemoryMetrics.scala index 23d95186..2fac118c 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/MemoryMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/MemoryMetrics.scala @@ -11,7 +11,7 @@ import org.hyperic.sigar.Sigar * - swap-used: Total used system swap.. * - swap-free: Total free system swap. */ -class MemoryMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class MemoryMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val used = histogram("memory-used", Memory.Bytes) val cached = histogram("memory-cache-and-buffer", Memory.Bytes) val free = histogram("memory-free", Memory.Bytes) @@ -19,7 +19,7 @@ class MemoryMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityR val swapUsed = histogram("swap-used", Memory.Bytes) val swapFree = histogram("swap-free", Memory.Bytes) - def update(sigar: Sigar): Unit = { + def update(): Unit = { val mem = sigar.getMem val swap = sigar.getSwap val cachedMemory = if (mem.getActualFree > mem.getFree) mem.getActualFree - mem.getFree else 0L @@ -35,7 +35,7 @@ class MemoryMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityR object MemoryMetrics extends SigarMetricRecorderCompanion("memory") { - def apply(instrumentFactory: InstrumentFactory): MemoryMetrics = - new MemoryMetrics(instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): MemoryMetrics = + new MemoryMetrics(sigar, instrumentFactory) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/NetworkMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/NetworkMetrics.scala index abdae99f..d9ba2bef 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/NetworkMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/NetworkMetrics.scala @@ -5,7 +5,7 @@ import kamon.metric.instrument._ import org.hyperic.sigar.{ NetInterfaceStat, Sigar } import scala.util.Try -class NetworkMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class NetworkMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val receivedBytes = DiffRecordingHistogram(histogram("rx-bytes", Memory.Bytes)) val transmittedBytes = DiffRecordingHistogram(histogram("tx-bytes", Memory.Bytes)) val receiveErrors = DiffRecordingHistogram(histogram("rx-errors")) @@ -13,13 +13,14 @@ class NetworkMetrics(instrumentFactory: InstrumentFactory) extends GenericEntity val receiveDrops = DiffRecordingHistogram(histogram("rx-dropped")) val transmitDrops = DiffRecordingHistogram(histogram("tx-dropped")) + val interfaces = sigar.getNetInterfaceList.toList.filter(_ != "lo") + def sumOfAllInterfaces(sigar: Sigar, thunk: NetInterfaceStat ⇒ Long): Long = Try { - val interfaces = sigar.getNetInterfaceList.toList.filter(_ != "lo") interfaces.map(i ⇒ thunk(sigar.getNetInterfaceStat(i))).fold(0L)(_ + _) } getOrElse (0L) - def update(sigar: Sigar): Unit = { + def update(): Unit = { receivedBytes.record(sumOfAllInterfaces(sigar, _.getRxBytes)) transmittedBytes.record(sumOfAllInterfaces(sigar, _.getTxBytes)) receiveErrors.record(sumOfAllInterfaces(sigar, _.getRxErrors)) @@ -30,6 +31,6 @@ class NetworkMetrics(instrumentFactory: InstrumentFactory) extends GenericEntity } object NetworkMetrics extends SigarMetricRecorderCompanion("network") { - def apply(instrumentFactory: InstrumentFactory): NetworkMetrics = - new NetworkMetrics(instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): NetworkMetrics = + new NetworkMetrics(sigar, instrumentFactory) }
\ No newline at end of file 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 0ca5c1c8..9a48f961 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 @@ -4,14 +4,14 @@ import kamon.metric.GenericEntityRecorder import kamon.metric.instrument.InstrumentFactory import org.hyperic.sigar.{ ProcCpu, Sigar } -class ProcessCpuMetrics(instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { +class ProcessCpuMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { val processUserCpu = histogram("process-user-cpu") val processSystemCpu = histogram("process-system-cpu") val processTotalCpu = histogram("process-cpu") var lastProcCpu: Option[ProcCpu] = None - def update(sigar: Sigar): Unit = { + def update(): Unit = { val pid = sigar.getPid val procCpu = sigar.getProcCpu(pid) @@ -34,6 +34,6 @@ class ProcessCpuMetrics(instrumentFactory: InstrumentFactory) extends GenericEnt object ProcessCpuMetrics extends SigarMetricRecorderCompanion("process-cpu") { - def apply(instrumentFactory: InstrumentFactory): ProcessCpuMetrics = - new ProcessCpuMetrics(instrumentFactory) + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): ProcessCpuMetrics = + new ProcessCpuMetrics(sigar, instrumentFactory) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala index 8a430427..2f709b61 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala @@ -14,12 +14,12 @@ class SigarMetricsUpdater(refreshInterval: FiniteDuration) extends Actor { val metricsExtension = Kamon(Metrics)(context.system) val sigarMetrics = List( - CpuMetrics.register(metricsExtension), - FileSystemMetrics.register(metricsExtension), - LoadAverageMetrics.register(metricsExtension), - MemoryMetrics.register(metricsExtension), - NetworkMetrics.register(metricsExtension), - ProcessCpuMetrics.register(metricsExtension)) + CpuMetrics.register(sigar, metricsExtension), + FileSystemMetrics.register(sigar, metricsExtension), + LoadAverageMetrics.register(sigar, metricsExtension), + MemoryMetrics.register(sigar, metricsExtension), + NetworkMetrics.register(sigar, metricsExtension), + ProcessCpuMetrics.register(sigar, metricsExtension)) val refreshSchedule = context.system.scheduler.schedule(refreshInterval, refreshInterval, self, UpdateSigarMetrics)(context.dispatcher) @@ -28,7 +28,7 @@ class SigarMetricsUpdater(refreshInterval: FiniteDuration) extends Actor { } def updateMetrics(): Unit = { - sigarMetrics.foreach(_.update(sigar)) + sigarMetrics.foreach(_.update()) } override def postStop(): Unit = { @@ -45,15 +45,15 @@ object SigarMetricsUpdater { } trait SigarMetric extends EntityRecorder { - def update(sigar: Sigar): Unit + def update(): Unit } abstract class SigarMetricRecorderCompanion(metricName: String) { - def register(metricsExtension: MetricsExtension): SigarMetric = { + def register(sigar: Sigar, metricsExtension: MetricsExtension): SigarMetric = { val instrumentFactory = metricsExtension.instrumentFactory("system-metric") - metricsExtension.register(Entity(metricName, "system-metric"), apply(instrumentFactory)).recorder + metricsExtension.register(Entity(metricName, "system-metric"), apply(sigar, instrumentFactory)).recorder } - def apply(instrumentFactory: InstrumentFactory): SigarMetric + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory): SigarMetric } |