Reputation: 1
double getCPUUsage() {
OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
return osBean.getProcessCpuLoad();
}
Cpu usage from above method is not giving as accurate cpu usage as kubernetes metrics.
This is same as spring boot metric system_cpu_usage
as it also uses the same OperatingSystemMXBean in its implementation.
Other methods to get cpu usage in java?
Upvotes: 0
Views: 121