Skip to content

Commit

Permalink
[INTERNAL] - Broker CPU utilization underestimated on Kubernetes
Browse files Browse the repository at this point in the history
See: linkedin#1242
This is an internal patch to use SystemCpuLoad to monitor broker pod
cpu usage knowing that we always run the broker in a container.

As `SystemCpuLoad` reports un-normalized cpu load across all cores
we do this normalization to match CC expected value in [0, 1] interval.
  • Loading branch information
amuraru committed Sep 18, 2020
1 parent 069d759 commit c91cdc6
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ public static CruiseControlMetric toCruiseControlMetric(long now,
* @return the "recent CPU usage" for the JVM process as a double in [0.0,1.0].
*/
public static BrokerMetric getCpuMetric(long now, int brokerId, boolean kubernetesMode) throws IOException {
double cpuUtil = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getProcessCpuLoad();

// we openjdk-14 runtime and get the process cpu utilization as system_load/no_of_processors
com.sun.management.OperatingSystemMXBean systemMXBean =
(com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
double cpuUtil = systemMXBean.getSystemCpuLoad() / systemMXBean.getAvailableProcessors();

if (kubernetesMode) {
cpuUtil = ContainerMetricUtils.getContainerProcessCpuLoad(cpuUtil);
Expand Down

0 comments on commit c91cdc6

Please sign in to comment.