From 9c82452b8252fbae754d208c0d2bedbe3a9505a2 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 6 Jul 2017 15:30:07 +0530 Subject: [PATCH] FIX3: Consider overcommit ratios with total/threshold values Consider the CPU and memory overcommit ratios with total cpu/ram values or thresholds for host and cluster metrics. This will fix incorrect notification (cells turning yellow/red) in the metrics view. Signed-off-by: Rohit Yadav --- .../cloudstack/response/ClusterMetricsResponse.java | 8 ++++---- .../apache/cloudstack/response/HostMetricsResponse.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/metrics/src/org/apache/cloudstack/response/ClusterMetricsResponse.java b/plugins/metrics/src/org/apache/cloudstack/response/ClusterMetricsResponse.java index 1ee2184d7a6..d1046f92924 100644 --- a/plugins/metrics/src/org/apache/cloudstack/response/ClusterMetricsResponse.java +++ b/plugins/metrics/src/org/apache/cloudstack/response/ClusterMetricsResponse.java @@ -174,13 +174,13 @@ public class ClusterMetricsResponse extends ClusterResponse { public void setCpuAllocatedThreshold(final Long cpuAllocated, final Long cpuUsed, final Double overCommitRatio, final Double threshold) { if (cpuAllocated != null && cpuUsed != null && overCommitRatio != null && threshold != null && cpuUsed != 0) { - this.cpuAllocatedThresholdExceeded = (1.0 * cpuAllocated * overCommitRatio / cpuUsed) > threshold; + this.cpuAllocatedThresholdExceeded = (1.0 * cpuAllocated / cpuUsed) > (threshold * overCommitRatio); } } public void setCpuAllocatedDisableThreshold(final Long cpuAllocated, final Long cpuUsed, final Double overCommitRatio, final Float threshold) { if (cpuAllocated != null && cpuUsed != null && overCommitRatio != null && threshold != null && cpuUsed != 0) { - this.cpuAllocatedDisableThresholdExceeded = (1.0 * cpuAllocated * overCommitRatio / cpuUsed) > threshold; + this.cpuAllocatedDisableThresholdExceeded = (1.0 * cpuAllocated / cpuUsed) > (threshold * overCommitRatio); } } @@ -199,13 +199,13 @@ public class ClusterMetricsResponse extends ClusterResponse { public void setMemoryAllocatedThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Double threshold) { if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null && memTotal != 0) { - this.memoryAllocatedThresholdExceeded = (1.0 * memAllocated * overCommitRatio / memTotal) > threshold; + this.memoryAllocatedThresholdExceeded = (1.0 * memAllocated / memTotal) > (threshold * overCommitRatio); } } public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Float threshold) { if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null && memTotal != 0) { - this.memoryAllocatedDisableThresholdExceeded = (1.0 * memAllocated * overCommitRatio / memTotal) > threshold; + this.memoryAllocatedDisableThresholdExceeded = (1.0 * memAllocated / memTotal) > (threshold * overCommitRatio); } } } diff --git a/plugins/metrics/src/org/apache/cloudstack/response/HostMetricsResponse.java b/plugins/metrics/src/org/apache/cloudstack/response/HostMetricsResponse.java index cdc9d16d845..72e9f92f803 100644 --- a/plugins/metrics/src/org/apache/cloudstack/response/HostMetricsResponse.java +++ b/plugins/metrics/src/org/apache/cloudstack/response/HostMetricsResponse.java @@ -167,13 +167,13 @@ public class HostMetricsResponse extends HostResponse { public void setCpuAllocatedThreshold(final String cpuAllocated, final Double overCommitRatio, final Double threshold) { if (cpuAllocated != null && overCommitRatio != null && threshold != null) { - this.cpuAllocatedThresholdExceeded = (Double.valueOf(cpuAllocated.replace("%", "")) * overCommitRatio) > (100.0 * threshold); + this.cpuAllocatedThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold * overCommitRatio); } } public void setCpuAllocatedDisableThreshold(final String cpuAllocated, final Double overCommitRatio, final Float threshold) { if (cpuAllocated != null && overCommitRatio != null && threshold != null) { - this.cpuAllocatedDisableThresholdExceeded = (Double.valueOf(cpuAllocated.replace("%", "")) * overCommitRatio) > (100.0 * threshold); + this.cpuAllocatedDisableThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold * overCommitRatio); } } @@ -191,13 +191,13 @@ public class HostMetricsResponse extends HostResponse { public void setMemoryAllocatedThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Double threshold) { if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null) { - this.memoryAllocatedThresholdExceeded = (memAllocated * overCommitRatio) > (memTotal * threshold); + this.memoryAllocatedThresholdExceeded = memAllocated > (memTotal * threshold * overCommitRatio); } } public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Float threshold) { if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null) { - this.memoryAllocatedDisableThresholdExceeded = (memAllocated * overCommitRatio) > (memTotal * threshold); + this.memoryAllocatedDisableThresholdExceeded = memAllocated > (memTotal * threshold * overCommitRatio); } }