diff options
author | Diego <diegolparra@gmail.com> | 2014-08-13 08:21:57 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-08-13 08:21:57 -0300 |
commit | 8b4a6a39c0f66033716fa576c65f2db485ae31a8 (patch) | |
tree | c317be941010953041dff12e97c3386278341054 /kamon-log-reporter/src/main/scala | |
parent | 79ccffe3fff870d8a9338576eff6caad7ed69992 (diff) | |
download | Kamon-8b4a6a39c0f66033716fa576c65f2db485ae31a8.tar.gz Kamon-8b4a6a39c0f66033716fa576c65f2db485ae31a8.tar.bz2 Kamon-8b4a6a39c0f66033716fa576c65f2db485ae31a8.zip |
+ console-reporter: include CPU and Network metrics
Diffstat (limited to 'kamon-log-reporter/src/main/scala')
-rw-r--r-- | kamon-log-reporter/src/main/scala/kamon/logreporter/LogReporter.scala | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/kamon-log-reporter/src/main/scala/kamon/logreporter/LogReporter.scala b/kamon-log-reporter/src/main/scala/kamon/logreporter/LogReporter.scala index 4fde7f92..6599d48d 100644 --- a/kamon-log-reporter/src/main/scala/kamon/logreporter/LogReporter.scala +++ b/kamon-log-reporter/src/main/scala/kamon/logreporter/LogReporter.scala @@ -23,8 +23,12 @@ import kamon.metric.ActorMetrics.ActorMetricSnapshot import kamon.metric.Subscriptions.TickMetricSnapshot import kamon.metric.TraceMetrics.TraceMetricsSnapshot import kamon.metric.UserMetrics._ -import kamon.metric.instrument.{ Counter, Histogram } import kamon.metric._ +import kamon.metric.instrument.{Counter, Histogram} +import kamon.metrics.MemoryMetrics.MemoryMetricSnapshot +import kamon.metrics.NetworkMetrics.NetworkMetricSnapshot +import kamon.metrics.{NetworkMetrics, MemoryMetrics, CPUMetrics} +import kamon.metrics.CPUMetrics.CPUMetricSnapshot object LogReporter extends ExtensionId[LogReporterExtension] with ExtensionIdProvider { override def lookup(): ExtensionId[_ <: Extension] = LogReporter @@ -51,10 +55,14 @@ class LogReporterExtension(system: ExtendedActorSystem) extends Kamon.Extension Kamon(Metrics)(system).subscribe(UserMinMaxCounters, "*", subscriber, permanently = true) Kamon(Metrics)(system).subscribe(UserGauges, "*", subscriber, permanently = true) + //Subscribe to all system metrics + Kamon(Metrics)(system).subscribe(CPUMetrics, "*", subscriber, permanently = true) + Kamon(Metrics)(system).subscribe(NetworkMetrics, "*", subscriber, permanently = true) + } class LogReporterSubscriber extends Actor with ActorLogging { - import LogReporterSubscriber.RichHistogramSnapshot + import kamon.logreporter.LogReporterSubscriber.RichHistogramSnapshot def receive = { case tick: TickMetricSnapshot ⇒ printMetricSnapshot(tick) @@ -74,6 +82,8 @@ class LogReporterSubscriber extends Actor with ActorLogging { case (c: UserCounter, s: UserCounterSnapshot) ⇒ counters += (c -> s.counterSnapshot) case (m: UserMinMaxCounter, s: UserMinMaxCounterSnapshot) ⇒ minMaxCounters += (m -> s.minMaxCounterSnapshot) case (g: UserGauge, s: UserGaugeSnapshot) ⇒ gauges += (g -> s.gaugeSnapshot) + case (_, cms:CPUMetricSnapshot) ⇒ logCpuMetrics(cms) + case (_, nms:NetworkMetricSnapshot) ⇒ logNetworkMetrics(nms) case ignoreEverythingElse ⇒ } @@ -110,6 +120,67 @@ class LogReporterSubscriber extends Actor with ActorLogging { ams.processingTime.max, ams.timeInMailbox.max)) } + def logCpuMetrics(cms: CPUMetricSnapshot):Unit = { + import cms._ + + log.info( + """ + |+--------------------------------------------------------------------------------------------------+ + || | + || CPU (ALL) | + || | + || User (percentage) System (percentage) Wait (percentage) Idle (percentage) | + || Min: %-3s Min: %-3s Min: %-3s Min: %-3s | + || 50th Perc: %-3s 50th Perc: %-3s 50th Perc: %-3s 50th Perc: %-3s | + || 90th Perc: %-3s 90th Perc: %-3s 90th Perc: %-3s 90th Perc: %-3s | + || 95th Perc: %-3s 95th Perc: %-3s 95th Perc: %-3s 95th Perc: %-3s | + || 99th Perc: %-3s 9th Perc: %-3s 99th Perc: %-3s 99th Perc: %-3s | + || 99.9th Perc: %-3s 9.9th Perc: %-3s 99.9th Perc: %-3s 99.9th Perc: %-3s | + || Max: %-3s Max: %-3s Max: %-3s Max: %-3s | + || | + || | + |+--------------------------------------------------------------------------------------------------+""" + .stripMargin.format( + user.min, system.min, cpuWait.min, idle.min, + user.percentile(0.50F), system.percentile(0.50F), cpuWait.percentile(0.50F), cpuWait.percentile(0.50F), + user.percentile(0.90F), system.percentile(0.90F), cpuWait.percentile(0.90F), cpuWait.percentile(0.90F), + user.percentile(0.95F), system.percentile(0.95F), cpuWait.percentile(0.95F), cpuWait.percentile(0.95F), + user.percentile(0.99F), system.percentile(0.99F), cpuWait.percentile(0.99F), cpuWait.percentile(0.99F), + user.percentile(0.999F), system.percentile(0.999F), cpuWait.percentile(0.999F), cpuWait.percentile(0.999F), + user.max, system.max, cpuWait.max, cpuWait.max)) + + } + + def logNetworkMetrics(nms: NetworkMetricSnapshot): Unit = { + import nms._ + + log.info( + """ + |+--------------------------------------------------------------------------------------------------+ + || | + || Network (ALL) | + || | + || Rx-Bytes (KB) Tx-Bytes (KB) Rx-Errors Tx-Errors | + || Min: %-4s Min: %-4s Total: %-8s Total: %-8s| + || 50th Perc: %-4s 50th Perc: %-4s | + || 90th Perc: %-4s 90th Perc: %-4s | + || 95th Perc: %-4s 95th Perc: %-4s | + || 99th Perc: %-4s 9th Perc: %-4s | + || 99.9th Perc: %-4s 99.9th Perc: %-4s | + || Max: %-4s Max: %-4s | + || | + |+--------------------------------------------------------------------------------------------------+""" + .stripMargin.format( + rxBytes.min, txBytes.min , rxErrors.total, txErrors.total, + rxBytes.percentile(0.50F), txBytes.percentile(0.50F), + rxBytes.percentile(0.90F), txBytes.percentile(0.90F), + rxBytes.percentile(0.95F), txBytes.percentile(0.95F), + rxBytes.percentile(0.99F), txBytes.percentile(0.99F), + rxBytes.percentile(0.999F), txBytes.percentile(0.999F), + rxBytes.max, txBytes.max)) + } + + def logTraceMetrics(name: String, tms: TraceMetricsSnapshot): Unit = { val traceMetricsData = StringBuilder.newBuilder @@ -248,5 +319,12 @@ object LogReporterSubscriber { return acc / histogram.numberOfMeasurements } + + def total: Long = { + histogram.recordsIterator.foldLeft(0L) { (acc, record) => { + acc + record.count * record.level + } + } + } } }
\ No newline at end of file |