Skip to content

Commit 90e7cab

Browse files
yadvrRohit Yadav
authored andcommitted
FIX3: Consider overcommit ratios with total/threshold values for host metrics
Consider the CPU and memory overcommit ratios with total cpu/ram values or thresholds for host metrics. This will fix incorrect notification (cells turning yellow/red) in the metrics view. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent c566aba commit 90e7cab

3 files changed

Lines changed: 20 additions & 23 deletions

File tree

plugins/metrics/src/org/apache/cloudstack/metrics/MetricsServiceImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ public List<ClusterMetricsResponse> listClusterMetrics(List<ClusterResponse> clu
316316
final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.valueIn(clusterId);
317317
final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.valueIn(clusterId);
318318

319-
final Double cpuOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "cpuOvercommitRatio"));
320-
final Double memoryOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "memoryOvercommitRatio"));
321-
322319
// CPU and memory capacities
323320
final CapacityDaoImpl.SummedCapacity cpuCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_CPU, null, clusterId);
324321
final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, null, clusterId);
@@ -351,13 +348,13 @@ public List<ClusterMetricsResponse> listClusterMetrics(List<ClusterResponse> clu
351348
// CPU thresholds
352349
metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuThreshold);
353350
metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuDisableThreshold);
354-
metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuOvercommitRatio, cpuThreshold);
355-
metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuOvercommitRatio, cpuDisableThreshold);
351+
metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuThreshold);
352+
metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuDisableThreshold);
356353
// Memory thresholds
357354
metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryThreshold);
358355
metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryDisableThreshold);
359-
metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryOvercommitRatio, memoryThreshold);
360-
metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryOvercommitRatio, memoryDisableThreshold);
356+
metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryThreshold);
357+
metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryDisableThreshold);
361358

362359
metricsResponses.add(metricsResponse);
363360
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ public void setCpuUsageDisableThreshold(final Double cpuUsed, final Long totalHo
172172
}
173173
}
174174

175-
public void setCpuAllocatedThreshold(final Long cpuAllocated, final Long cpuUsed, final Double overCommitRatio, final Double threshold) {
176-
if (cpuAllocated != null && cpuUsed != null && overCommitRatio != null && threshold != null && cpuUsed != 0) {
177-
this.cpuAllocatedThresholdExceeded = (1.0 * cpuAllocated * overCommitRatio / cpuUsed) > threshold;
175+
public void setCpuAllocatedThreshold(final Long cpuAllocated, final Long cpuTotal, final Double threshold) {
176+
if (cpuAllocated != null && cpuTotal != null && threshold != null && cpuTotal != 0) {
177+
this.cpuAllocatedThresholdExceeded = (1.0 * cpuAllocated / cpuTotal) > threshold;
178178
}
179179
}
180180

181-
public void setCpuAllocatedDisableThreshold(final Long cpuAllocated, final Long cpuUsed, final Double overCommitRatio, final Float threshold) {
182-
if (cpuAllocated != null && cpuUsed != null && overCommitRatio != null && threshold != null && cpuUsed != 0) {
183-
this.cpuAllocatedDisableThresholdExceeded = (1.0 * cpuAllocated * overCommitRatio / cpuUsed) > threshold;
181+
public void setCpuAllocatedDisableThreshold(final Long cpuAllocated, final Long cpuTotal, final Float threshold) {
182+
if (cpuAllocated != null && cpuTotal != null && threshold != null && cpuTotal != 0) {
183+
this.cpuAllocatedDisableThresholdExceeded = (1.0 * cpuAllocated / cpuTotal) > threshold;
184184
}
185185
}
186186

@@ -197,15 +197,15 @@ public void setMemoryUsageDisableThreshold(final Long memUsed, final Long memTot
197197
}
198198

199199

200-
public void setMemoryAllocatedThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Double threshold) {
201-
if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null && memTotal != 0) {
202-
this.memoryAllocatedThresholdExceeded = (1.0 * memAllocated * overCommitRatio / memTotal) > threshold;
200+
public void setMemoryAllocatedThreshold(final Long memAllocated, final Long memTotal, final Double threshold) {
201+
if (memAllocated != null && memTotal != null && threshold != null && memTotal != 0) {
202+
this.memoryAllocatedThresholdExceeded = (1.0 * memAllocated / memTotal) > threshold;
203203
}
204204
}
205205

206-
public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Float threshold) {
207-
if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null && memTotal != 0) {
208-
this.memoryAllocatedDisableThresholdExceeded = (1.0 * memAllocated * overCommitRatio / memTotal) > threshold;
206+
public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Long memTotal, final Float threshold) {
207+
if (memAllocated != null && memTotal != null && threshold != null && memTotal != 0) {
208+
this.memoryAllocatedDisableThresholdExceeded = (1.0 * memAllocated / memTotal) > threshold;
209209
}
210210
}
211211
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ public void setCpuUsageDisableThreshold(final String cpuUsed, final Float thresh
167167

168168
public void setCpuAllocatedThreshold(final String cpuAllocated, final Double overCommitRatio, final Double threshold) {
169169
if (cpuAllocated != null && overCommitRatio != null && threshold != null) {
170-
this.cpuAllocatedThresholdExceeded = (Double.valueOf(cpuAllocated.replace("%", "")) * overCommitRatio) > (100.0 * threshold);
170+
this.cpuAllocatedThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold * overCommitRatio);
171171
}
172172
}
173173

174174
public void setCpuAllocatedDisableThreshold(final String cpuAllocated, final Double overCommitRatio, final Float threshold) {
175175
if (cpuAllocated != null && overCommitRatio != null && threshold != null) {
176-
this.cpuAllocatedDisableThresholdExceeded = (Double.valueOf(cpuAllocated.replace("%", "")) * overCommitRatio) > (100.0 * threshold);
176+
this.cpuAllocatedDisableThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold * overCommitRatio);
177177
}
178178
}
179179

@@ -191,13 +191,13 @@ public void setMemoryUsageDisableThreshold(final Long memUsed, final Long memTot
191191

192192
public void setMemoryAllocatedThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Double threshold) {
193193
if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null) {
194-
this.memoryAllocatedThresholdExceeded = (memAllocated * overCommitRatio) > (memTotal * threshold);
194+
this.memoryAllocatedThresholdExceeded = memAllocated > (memTotal * threshold * overCommitRatio);
195195
}
196196
}
197197

198198
public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Long memTotal, final Double overCommitRatio, final Float threshold) {
199199
if (memAllocated != null && memTotal != null && overCommitRatio != null && threshold != null) {
200-
this.memoryAllocatedDisableThresholdExceeded = (memAllocated * overCommitRatio) > (memTotal * threshold);
200+
this.memoryAllocatedDisableThresholdExceeded = memAllocated > (memTotal * threshold * overCommitRatio);
201201
}
202202
}
203203

0 commit comments

Comments
 (0)