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 May 11, 2022
1 parent 4fd455a commit fa28a0f
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,15 @@ private static CruiseControlMetric toCruiseControlMetric(long nowMs,
* @return the "recent CPU usage" for the JVM process as a double in [0.0,1.0].
*/
public static BrokerMetric getCpuMetric(long nowMs, int brokerId, boolean kubernetesMode) throws IOException {
double cpuUtil = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getProcessCpuLoad();

double cpuUtil;
if (kubernetesMode) {
cpuUtil = ContainerMetricUtils.getContainerProcessCpuLoad(cpuUtil);
// we are using openjdk>=14 runtime in k8s environments so
// the process cpu utilization is computed as: system_load/no_of_processors
com.sun.management.OperatingSystemMXBean systemMXBean =
(com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
cpuUtil = systemMXBean.getSystemCpuLoad() / systemMXBean.getAvailableProcessors();
} else {
cpuUtil = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getProcessCpuLoad();
}

if (cpuUtil < 0) {
Expand Down

0 comments on commit fa28a0f

Please sign in to comment.