diff options
author | Diego <diegolparra@gmail.com> | 2014-08-16 23:13:56 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-08-16 23:13:56 -0300 |
commit | 92a258f5f5e54cde7c7c85bfd76a2f9d7c532551 (patch) | |
tree | 644f83355041021b3ed7a1e342bf50a740880ad5 /kamon-system-metrics/src/main/scala | |
parent | 9fe3750f7cf8b3a85f7db8ebd1cc8daff097935e (diff) | |
download | Kamon-92a258f5f5e54cde7c7c85bfd76a2f9d7c532551.tar.gz Kamon-92a258f5f5e54cde7c7c85bfd76a2f9d7c532551.tar.bz2 Kamon-92a258f5f5e54cde7c7c85bfd76a2f9d7c532551.zip |
+ log-reporter: include Process Cpu metrics and closes #72
Diffstat (limited to 'kamon-system-metrics/src/main/scala')
3 files changed, 41 insertions, 17 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala index 61f7ddb2..21f76a12 100644 --- a/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala @@ -27,31 +27,31 @@ case class ProcessCPUMetrics(name: String) extends MetricGroupIdentity { 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 object CpuPercent extends MetricIdentity { val name = "cpu-percentage" } + case object TotalProcessTime extends MetricIdentity { val name = "total-process-time" } - case class ProcessCPUMetricsRecorder(user: Histogram, system: Histogram) + case class ProcessCPUMetricsRecorder(cpuPercent: Histogram, totalProcessTime: Histogram) extends MetricGroupRecorder { def collect(context: CollectionContext): MetricGroupSnapshot = { - ProcessCPUMetricsSnapshot(user.collect(context), system.collect(context)) + ProcessCPUMetricsSnapshot(cpuPercent.collect(context), totalProcessTime.collect(context)) } def cleanup: Unit = {} } - case class ProcessCPUMetricsSnapshot(user: Histogram.Snapshot, system: Histogram.Snapshot) + case class ProcessCPUMetricsSnapshot(cpuPercent: Histogram.Snapshot, totalProcessTime: 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)) + ProcessCPUMetricsSnapshot(cpuPercent.merge(that.cpuPercent, context), totalProcessTime.merge(that.totalProcessTime, context)) } lazy val metrics: Map[MetricIdentity, MetricSnapshot] = Map( - User -> user, - System -> system) + CpuPercent -> cpuPercent, + TotalProcessTime -> totalProcessTime) } val Factory = new MetricGroupFactory { @@ -61,12 +61,12 @@ object ProcessCPUMetrics extends MetricGroupCategory { 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") + val cpuPercentageConfig = settings.getConfig("cpu-percentage") + val totalProcessTimeConfig = settings.getConfig("total-process-time") new ProcessCPUMetricsRecorder( - Histogram.fromConfig(userConfig), - Histogram.fromConfig(systemConfig)) + Histogram.fromConfig(cpuPercentageConfig), + Histogram.fromConfig(totalProcessTimeConfig)) } } } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala b/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala index 31963487..725f634d 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala @@ -64,9 +64,10 @@ class SystemMetricsCollector(collectInterval: FiniteDuration) extends Actor with private def recordProcessCpu(pcpur: ProcessCPUMetricsRecorder) = { val procCpu = sigar.getProcCpu(pid) + val procTime = sigar.getProcTime(pid) - pcpur.user.record(procCpu.getUser) - pcpur.system.record(procCpu.getSys) + pcpur.cpuPercent.record(toLong(procCpu.getPercent)) + pcpur.totalProcessTime.record(procTime.getTotal) // gives an idea of what is really measured and then interpreted as % } private def recordMemory(mr: MemoryMetricRecorder) = { diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala index af49fca5..36e62756 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala @@ -142,10 +142,33 @@ object SigarLoader { } def uptime(sigar: Sigar) = { - val sdf = new SimpleDateFormat("yyyy-MM-dd") + def formatUptime(uptime: Double): String = { + var retval: String = "" + val days: Int = uptime.toInt / (60 * 60 * 24) + var minutes: Int = 0 + var hours: Int = 0 + + if (days != 0) { + retval += s"$days ${(if ((days > 1)) "days" else "day")}, " + } + + minutes = uptime.toInt / 60 + hours = minutes / 60 + hours %= 24 + minutes %= 60 + + if (hours != 0) { + retval += hours + ":" + minutes + } else { + retval += minutes + " min" + } + retval + } + val uptime = sigar.getUptime val now = System.currentTimeMillis() - sdf.format(new Date(now - (uptime.getUptime() * 1000).toLong)) + + s"up ${formatUptime(uptime.getUptime())}" } val message = @@ -162,7 +185,7 @@ object SigarLoader { | | [System Status] [OS Information] | |--------------------------------| |----------------------------------------| - | Boot Time: %-10s Description: %s + | Up Time: %-10s Description: %s | Load Average: %-16s Name: %s | Version: %s | Arch: %s |