Skip to content

Commit efe7646

Browse files
committed
CLOUDSTACK-9900: Fix high CPU deviation issues seen in metrics view
HostStats returns cpu usage in percentage while memory usage in bytes. This fixes a regression in maximum CPU usage deviation that did not assume the values to be in percentage and multiple the final ratios with 100 which leads to 100x the actual deviation value. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent bdc4fd7 commit efe7646

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

plugins/metrics/src/org/apache/cloudstack/response/ClusterMetricsResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ public void setCpuAllocated(final Long cpuAllocated, final Long cpuTotal) {
128128
}
129129
}
130130

131-
public void setCpuMaxDeviation(final Double maxCpuDeviation, final Double totalCpuUsed, final Long totalHosts) {
132-
if (maxCpuDeviation != null && totalCpuUsed != null && totalHosts != null && totalHosts != 0) {
133-
final Double averageCpuUsage = totalCpuUsed / totalHosts;
134-
this.cpuMaxDeviation = String.format("%.2f%%", (maxCpuDeviation - averageCpuUsage) * 100.0 / averageCpuUsage);
131+
public void setCpuMaxDeviation(final Double maxCpuUsagePercentage, final Double totalCpuUsedPercentage, final Long totalHosts) {
132+
if (maxCpuUsagePercentage != null && totalCpuUsedPercentage != null && totalHosts != null && totalHosts != 0) {
133+
final Double averageCpuUsagePercentage = totalCpuUsedPercentage / totalHosts;
134+
this.cpuMaxDeviation = String.format("%.2f%%", (maxCpuUsagePercentage - averageCpuUsagePercentage) / averageCpuUsagePercentage);
135135
}
136136
}
137137

plugins/metrics/src/org/apache/cloudstack/response/ZoneMetricsResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public void setCpuAllocated(final Long cpuAllocated, final Long cpuTotal) {
123123
}
124124
}
125125

126-
public void setCpuMaxDeviation(final Double maxCpuDeviation, final Double totalCpuUsed, final Long totalHosts) {
127-
if (maxCpuDeviation != null && totalCpuUsed != null && totalHosts != null && totalHosts != 0) {
128-
final Double averageCpuUsage = totalCpuUsed / totalHosts;
129-
this.cpuMaxDeviation = String.format("%.2f%%", (maxCpuDeviation - averageCpuUsage) * 100.0 / averageCpuUsage);
126+
public void setCpuMaxDeviation(final Double maxCpuUsagePercentage, final Double totalCpuUsedPercentage, final Long totalHosts) {
127+
if (maxCpuUsagePercentage != null && totalCpuUsedPercentage != null && totalHosts != null && totalHosts != 0) {
128+
final Double averageCpuUsagePercentage = totalCpuUsedPercentage / totalHosts;
129+
this.cpuMaxDeviation = String.format("%.2f%%", (maxCpuUsagePercentage - averageCpuUsagePercentage) / averageCpuUsagePercentage);
130130
}
131131
}
132132

0 commit comments

Comments
 (0)