You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by ca...@apache.org on 2022/04/06 18:02:37 UTC
[samza] branch master updated: SAMZA-2730: Add process CPU usage metric using units of processor count instead of percentage (#1593)
This is an automated email from the ASF dual-hosted git repository.
cameronlee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/samza.git
The following commit(s) were added to refs/heads/master by this push:
new e37fe259c SAMZA-2730: Add process CPU usage metric using units of processor count instead of percentage (#1593)
e37fe259c is described below
commit e37fe259cede587928cc0d543fc8384250c7e113
Author: Cameron Lee <ca...@linkedin.com>
AuthorDate: Wed Apr 6 11:02:29 2022 -0700
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.
---
docs/learn/documentation/versioned/container/metrics-table.html | 4 ++++
.../src/main/scala/org/apache/samza/metrics/JvmMetrics.scala | 9 ++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/docs/learn/documentation/versioned/container/metrics-table.html b/docs/learn/documentation/versioned/container/metrics-table.html
index b7cd752b4..869dd7d9a 100644
--- a/docs/learn/documentation/versioned/container/metrics-table.html
+++ b/docs/learn/documentation/versioned/container/metrics-table.html
@@ -355,6 +355,10 @@
<td>process-cpu-usage</td>
<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>
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 7cc145210..e05a2b8f9 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 @@ class JvmMetrics(val registry: MetricsRegistry) extends MetricsHelper with Runna
// 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 @@ class JvmMetrics(val registry: MetricsRegistry) extends MetricsHelper with Runna
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 @@ class JvmMetrics(val registry: MetricsRegistry) extends MetricsHelper with Runna
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]) {