aboutsummaryrefslogtreecommitdiff
path: root/kamon-system-metrics
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-08-16 23:13:56 -0300
committerDiego <diegolparra@gmail.com>2014-08-16 23:13:56 -0300
commit92a258f5f5e54cde7c7c85bfd76a2f9d7c532551 (patch)
tree644f83355041021b3ed7a1e342bf50a740880ad5 /kamon-system-metrics
parent9fe3750f7cf8b3a85f7db8ebd1cc8daff097935e (diff)
downloadKamon-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')
-rw-r--r--kamon-system-metrics/src/main/resources/reference.conf10
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/metrics/ProcessCPUMetrics.scala24
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/system/SystemMetricsCollector.scala5
-rw-r--r--kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala29
-rw-r--r--kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala6
5 files changed, 46 insertions, 28 deletions
diff --git a/kamon-system-metrics/src/main/resources/reference.conf b/kamon-system-metrics/src/main/resources/reference.conf
index 0600388d..e5315223 100644
--- a/kamon-system-metrics/src/main/resources/reference.conf
+++ b/kamon-system-metrics/src/main/resources/reference.conf
@@ -7,13 +7,11 @@ kamon {
precision {
system {
process-cpu {
- user = {
- refresh-interval = 100 milliseconds
+ cpu-percentage = {
highest-trackable-value = 999999999
significant-value-digits = 2
}
- system = {
- refresh-interval = 100 milliseconds
+ total-process-time = {
highest-trackable-value = 999999999
significant-value-digits = 2
}
@@ -21,22 +19,18 @@ kamon {
cpu {
user = {
- refresh-interval = 100 milliseconds
highest-trackable-value = 999
significant-value-digits = 2
}
system = {
- refresh-interval = 100 milliseconds
highest-trackable-value = 999
significant-value-digits = 2
}
wait = {
- refresh-interval = 100 milliseconds
highest-trackable-value = 999
significant-value-digits = 2
}
idle ={
- refresh-interval = 100 milliseconds
highest-trackable-value = 999
significant-value-digits = 2
}
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
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 cda820fc..461fd493 100644
--- a/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala
+++ b/kamon-system-metrics/src/test/scala/kamon/metrics/SystemMetricsSpec.scala
@@ -205,12 +205,12 @@ class SystemMetricsSpec extends TestKitBase with WordSpecLike with Matchers {
}
"the Kamon Process CPU Metrics" should {
- "record user, system metrics" in new ProcessCPUMetricsListenerFixture {
+ "record Cpu Percent, Total ProcessbTime metrics" in new ProcessCPUMetricsListenerFixture {
val metricsListener = subscribeToMetrics()
val ProcessCPUMetrics = expectProcessCPUMetrics(metricsListener, 3 seconds)
- ProcessCPUMetrics.user.max should be > 0L
- ProcessCPUMetrics.system.max should be > 0L
+ ProcessCPUMetrics.cpuPercent.max should be > 0L
+ ProcessCPUMetrics.totalProcessTime.max should be > 0L
}
}