Skip to content

Commit

Permalink
fix cpuUsage type
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc committed Jul 28, 2022
1 parent 92b41b6 commit 3e6d1b7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public static double getTotalCpuLimit(boolean isCGroupsEnabled) {
* @return Cpu usage
*/
@SneakyThrows
public static double getCpuUsageForCGroup() {
public static long getCpuUsageForCGroup() {
if (getCpuUsageMethod == null) {
return -1;
}
return (double) getCpuUsageMethod.invoke(metrics);
return (long) getCpuUsageMethod.invoke(metrics);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private double getTotalCpuUsage(double elapsedTimeSeconds) {
}

private double getTotalCpuUsageForCGroup(double elapsedTimeSeconds) {
double usage = getCpuUsageForCGroup();
double usage = (double) getCpuUsageForCGroup();
double currentUsage = usage - lastCpuUsage;
lastCpuUsage = usage;
return 100 * currentUsage / elapsedTimeSeconds / TimeUnit.SECONDS.toNanos(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testCGroupMetrics() throws IOException {
Assert.assertEquals(totalCpuLimit, expectTotalCpuLimit);

if (cGroupEnabled) {
double cpuUsageForCGroup = LinuxInfoUtils.getCpuUsageForCGroup();
long cpuUsageForCGroup = LinuxInfoUtils.getCpuUsageForCGroup();
log.info("cpuUsageForCGroup: {}", cpuUsageForCGroup);
}
}
Expand Down

0 comments on commit 3e6d1b7

Please sign in to comment.