SAMZA-2730: Add process CPU usage metric using units of processor count instead of percentage (#1593)
API/usage changes: (backwards compatible) An extra metric process-cpu-usage-processors is now available which reports the number of processors being used.
diff --git a/docs/learn/documentation/versioned/container/metrics-table.html b/docs/learn/documentation/versioned/container/metrics-table.html
index b7cd752..869dd7d 100644
--- a/docs/learn/documentation/versioned/container/metrics-table.html
+++ b/docs/learn/documentation/versioned/container/metrics-table.html
@@ -356,6 +356,10 @@
<td>Current CPU usage of the JVM process as a percentage from 0 to 100. The percentage represents the proportion of executed ticks by the JVM process to the total ticks across all CPUs. A negative number indicates the value was not available from the operating system. For more detail, see the JavaDoc for com.sun.management.OperatingSystemMXBean.</td>
</tr>
<tr>
+ <td>process-cpu-usage-processors</td>
+ <td>Number of processors currently in use by the JVM process, calculated by multiplying the usage percentage by the total number of processors. A negative number indicates that there was not enough information available to calculate this value. For more detail, see the JavaDoc for com.sun.management.OperatingSystemMXBean.</td>
+ </tr>
+ <tr>
<td>system-cpu-usage</td>
<td>Current CPU usage of the all processes in the whole system as a percentage from 0 to 100. The percentage represents the proportion of executed ticks by all processes to the total ticks across all CPUs. A negative number indicates the value was not available from the operating system. For more detail, see the JavaDoc for com.sun.management.OperatingSystemMXBean.</td>
</tr>
diff --git a/samza-core/src/main/scala/org/apache/samza/metrics/JvmMetrics.scala b/samza-core/src/main/scala/org/apache/samza/metrics/JvmMetrics.scala
index 7cc1452..e05a2b8 100644
--- a/samza-core/src/main/scala/org/apache/samza/metrics/JvmMetrics.scala
+++ b/samza-core/src/main/scala/org/apache/samza/metrics/JvmMetrics.scala
@@ -65,6 +65,7 @@
// Conditional metrics. Only emitted if the Operating System supports it.
val gProcessCpuUsage = if (osMXBean.isInstanceOf[OperatingSystemMXBean]) newGauge("process-cpu-usage", 0.0) else null
+ val gProcessCpuUsageProcessors = if (osMXBean.isInstanceOf[OperatingSystemMXBean]) newGauge("process-cpu-usage-processors", 0.0) else null
val gSystemCpuUsage = if (osMXBean.isInstanceOf[OperatingSystemMXBean]) newGauge("system-cpu-usage", 0.0) else null
val gOpenFileDescriptorCount = if (osMXBean.isInstanceOf[UnixOperatingSystemMXBean]) newGauge("open-file-descriptor-count", 0.0) else null
@@ -80,10 +81,10 @@
updateThreadUsage
updateOperatingSystemMetrics
- debug("updated metrics to: [%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s]" format
+ debug("updated metrics to: [%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s]" format
(gMemNonHeapUsedM, gMemNonHeapCommittedM, gMemNonHeapMaxM, gMemHeapUsedM, gMemHeapCommittedM,gMemHeapMaxM, gThreadsNew,
gThreadsRunnable, gThreadsBlocked, gThreadsWaiting, gThreadsTimedWaiting,
- gThreadsTerminated, cGcCount, cGcTimeMillis, gProcessCpuUsage, gSystemCpuUsage, gOpenFileDescriptorCount))
+ gThreadsTerminated, cGcCount, cGcTimeMillis, gProcessCpuUsage, gProcessCpuUsageProcessors, gSystemCpuUsage, gOpenFileDescriptorCount))
}
def stop = executor.shutdown
@@ -163,7 +164,9 @@
private def updateOperatingSystemMetrics {
if (osMXBean.isInstanceOf[OperatingSystemMXBean]) {
val operatingSystemMXBean = osMXBean.asInstanceOf[OperatingSystemMXBean]
- gProcessCpuUsage.set(operatingSystemMXBean.getProcessCpuLoad * PCT)
+ val processCpuLoad = operatingSystemMXBean.getProcessCpuLoad
+ gProcessCpuUsage.set(processCpuLoad * PCT)
+ gProcessCpuUsageProcessors.set(processCpuLoad * operatingSystemMXBean.getAvailableProcessors)
gSystemCpuUsage.set(operatingSystemMXBean.getSystemCpuLoad * PCT)
if (osMXBean.isInstanceOf[UnixOperatingSystemMXBean]) {