mirror of https://github.com/apache/cloudstack.git
api/server: cpu, memory values with overprovisioning in metrics response (#4795)
* metrics: operprovisioned host cpu allocated Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * remove unused Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
cc7f426564
commit
755791089d
|
|
@ -347,10 +347,6 @@ public class HostResponse extends BaseResponse {
|
|||
this.cpuSpeed = cpuSpeed;
|
||||
}
|
||||
|
||||
public String getCpuAllocated() {
|
||||
return cpuAllocated;
|
||||
}
|
||||
|
||||
public void setCpuAllocated(String cpuAllocated) {
|
||||
this.cpuAllocated = cpuAllocated;
|
||||
}
|
||||
|
|
@ -622,6 +618,10 @@ public class HostResponse extends BaseResponse {
|
|||
return cpuUsed;
|
||||
}
|
||||
|
||||
public String getCpuAllocated() {
|
||||
return cpuAllocated;
|
||||
}
|
||||
|
||||
public Double getAverageLoad() {
|
||||
return cpuloadaverage;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,9 +264,6 @@ public class MetricsServiceImpl extends ComponentLifecycleBase implements Metric
|
|||
final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.valueIn(clusterId);
|
||||
final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.valueIn(clusterId);
|
||||
final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.valueIn(clusterId);
|
||||
// Over commit ratios
|
||||
final Double cpuOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "cpuOvercommitRatio"));
|
||||
final Double memoryOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "memoryOvercommitRatio"));
|
||||
|
||||
Long upInstances = 0L;
|
||||
Long totalInstances = 0L;
|
||||
|
|
@ -283,11 +280,11 @@ public class MetricsServiceImpl extends ComponentLifecycleBase implements Metric
|
|||
}
|
||||
metricsResponse.setPowerState(hostResponse.getOutOfBandManagementResponse().getPowerState());
|
||||
metricsResponse.setInstances(upInstances, totalInstances);
|
||||
metricsResponse.setCpuTotal(hostResponse.getCpuNumber(), hostResponse.getCpuSpeed(), cpuOvercommitRatio);
|
||||
metricsResponse.setCpuTotal(hostResponse.getCpuNumber(), hostResponse.getCpuSpeed());
|
||||
metricsResponse.setCpuUsed(hostResponse.getCpuUsed(), hostResponse.getCpuNumber(), hostResponse.getCpuSpeed());
|
||||
metricsResponse.setCpuAllocated(hostResponse.getCpuAllocated(), hostResponse.getCpuNumber(), hostResponse.getCpuSpeed());
|
||||
metricsResponse.setLoadAverage(hostResponse.getAverageLoad());
|
||||
metricsResponse.setMemTotal(hostResponse.getMemoryTotal(), memoryOvercommitRatio);
|
||||
metricsResponse.setMemTotal(hostResponse.getMemoryTotal());
|
||||
metricsResponse.setMemAllocated(hostResponse.getMemoryAllocated());
|
||||
metricsResponse.setMemUsed(hostResponse.getMemoryUsed());
|
||||
metricsResponse.setNetworkRead(hostResponse.getNetworkKbsRead());
|
||||
|
|
@ -295,13 +292,13 @@ public class MetricsServiceImpl extends ComponentLifecycleBase implements Metric
|
|||
// CPU thresholds
|
||||
metricsResponse.setCpuUsageThreshold(hostResponse.getCpuUsed(), cpuThreshold);
|
||||
metricsResponse.setCpuUsageDisableThreshold(hostResponse.getCpuUsed(), cpuDisableThreshold);
|
||||
metricsResponse.setCpuAllocatedThreshold(hostResponse.getCpuAllocated(), cpuOvercommitRatio, cpuThreshold);
|
||||
metricsResponse.setCpuAllocatedDisableThreshold(hostResponse.getCpuAllocated(), cpuOvercommitRatio, cpuDisableThreshold);
|
||||
metricsResponse.setCpuAllocatedThreshold(hostResponse.getCpuAllocated(), cpuThreshold);
|
||||
metricsResponse.setCpuAllocatedDisableThreshold(hostResponse.getCpuAllocated(), cpuDisableThreshold);
|
||||
// Memory thresholds
|
||||
metricsResponse.setMemoryUsageThreshold(hostResponse.getMemoryUsed(), hostResponse.getMemoryTotal(), memoryThreshold);
|
||||
metricsResponse.setMemoryUsageDisableThreshold(hostResponse.getMemoryUsed(), hostResponse.getMemoryTotal(), memoryDisableThreshold);
|
||||
metricsResponse.setMemoryAllocatedThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryOvercommitRatio, memoryThreshold);
|
||||
metricsResponse.setMemoryAllocatedDisableThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryOvercommitRatio, memoryDisableThreshold);
|
||||
metricsResponse.setMemoryAllocatedThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryThreshold);
|
||||
metricsResponse.setMemoryAllocatedDisableThreshold(hostResponse.getMemoryAllocated(), hostResponse.getMemoryTotal(), memoryDisableThreshold);
|
||||
metricsResponses.add(metricsResponse);
|
||||
}
|
||||
return metricsResponses;
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@
|
|||
|
||||
package org.apache.cloudstack.response;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement;
|
||||
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class HostMetricsResponse extends HostResponse {
|
||||
@SerializedName("powerstate")
|
||||
@Param(description = "out-of-band management power state")
|
||||
|
|
@ -109,9 +110,9 @@ public class HostMetricsResponse extends HostResponse {
|
|||
}
|
||||
}
|
||||
|
||||
public void setCpuTotal(final Integer cpuNumber, final Long cpuSpeed, final Double overcommitRatio) {
|
||||
if (cpuNumber != null && cpuSpeed != null && overcommitRatio != null) {
|
||||
this.cpuTotal = String.format("%.2f Ghz (x %.1f)", cpuNumber * cpuSpeed / 1000.0, overcommitRatio);
|
||||
public void setCpuTotal(final Integer cpuNumber, final Long cpuSpeed) {
|
||||
if (cpuNumber != null && cpuSpeed != null) {
|
||||
this.cpuTotal = String.format("%.2f Ghz", cpuNumber * cpuSpeed / 1000.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,9 +134,9 @@ public class HostMetricsResponse extends HostResponse {
|
|||
}
|
||||
}
|
||||
|
||||
public void setMemTotal(final Long memTotal, final Double overcommitRatio) {
|
||||
if (memTotal != null && overcommitRatio != null) {
|
||||
this.memTotal = String.format("%.2f GB (x %.1f)", memTotal / (1024.0 * 1024.0 * 1024.0), overcommitRatio);
|
||||
public void setMemTotal(final Long memTotal) {
|
||||
if (memTotal != null) {
|
||||
this.memTotal = String.format("%.2f GB", memTotal / (1024.0 * 1024.0 * 1024.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,15 +176,15 @@ 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("%", "")) > (100.0 * threshold * overCommitRatio);
|
||||
public void setCpuAllocatedThreshold(final String cpuAllocated, final Double threshold) {
|
||||
if (cpuAllocated != null && threshold != null) {
|
||||
this.cpuAllocatedThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold );
|
||||
}
|
||||
}
|
||||
|
||||
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("%", "")) > (100.0 * threshold * overCommitRatio);
|
||||
public void setCpuAllocatedDisableThreshold(final String cpuAllocated, final Float threshold) {
|
||||
if (cpuAllocated != null && threshold != null) {
|
||||
this.cpuAllocatedDisableThresholdExceeded = Double.valueOf(cpuAllocated.replace("%", "")) > (100.0 * threshold);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -199,15 +200,15 @@ 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 > (memTotal * threshold * overCommitRatio);
|
||||
public void setMemoryAllocatedThreshold(final Long memAllocated, final Long memTotal, final Double threshold) {
|
||||
if (memAllocated != null && memTotal != null && threshold != null) {
|
||||
this.memoryAllocatedThresholdExceeded = memAllocated > (memTotal * threshold);
|
||||
}
|
||||
}
|
||||
|
||||
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 > (memTotal * threshold * overCommitRatio);
|
||||
public void setMemoryAllocatedDisableThreshold(final Long memAllocated, final Long memTotal, final Float threshold) {
|
||||
if (memAllocated != null && memTotal != null && threshold != null) {
|
||||
this.memoryAllocatedDisableThresholdExceeded = memAllocated > (memTotal * threshold);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,13 +163,15 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
|||
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
if (host.getType() == Host.Type.Routing) {
|
||||
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
|
||||
hostResponse.setCpuNumber((int)(host.getCpus() * cpuOverprovisioningFactor));
|
||||
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
|
||||
// set allocated capacities
|
||||
Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
|
||||
Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity();
|
||||
|
||||
hostResponse.setMemoryTotal(host.getTotalMemory());
|
||||
Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
|
||||
hostResponse.setMemoryTotal(memWithOverprovisioning.longValue());
|
||||
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
|
||||
hostResponse.setMemoryAllocated(mem);
|
||||
hostResponse.setMemoryAllocatedBytes(mem);
|
||||
|
|
@ -188,12 +190,12 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
|||
|
||||
hostResponse.setHypervisorVersion(host.getHypervisorVersion());
|
||||
|
||||
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * cpuOverprovisioningFactor;
|
||||
hostResponse.setCpuAllocatedValue(cpu);
|
||||
String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%";
|
||||
hostResponse.setCpuAllocated(cpuAlloc);
|
||||
hostResponse.setCpuAllocatedPercentage(cpuAlloc);
|
||||
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
|
||||
hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
|
||||
String cpuAllocated = calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning);
|
||||
hostResponse.setCpuAllocated(cpuAllocated);
|
||||
hostResponse.setCpuAllocatedPercentage(cpuAllocated);
|
||||
hostResponse.setCpuAllocatedWithOverprovisioning(cpuAllocated);
|
||||
hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue