Martin Sivák has uploaded a new change for review. Change subject: restapi: Account for ballooning in VM's memory.used ......................................................................
restapi: Account for ballooning in VM's memory.used When ballooning is used with a VM the memory used percentage value is computed from the available memory only. This accounts for that behaviour and uses the balloon information if available. Change-Id: If99f073c34ea6a5ba3743e431fc2b03719dd3f48 Signed-off-by: Martin Sivak <msi...@redhat.com> --- M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/VmStatisticalQuery.java 3 files changed, 18 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/19618/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java index f48e275..ff09663 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java @@ -1485,6 +1485,22 @@ balloonEnabled = isBallonEnabled; } + /** + * Get the amount of memory that is currently available to the VM + * with ballooning taken into consideration. + * If ballooning is not enabled, return the configured memory size. + * @return maximum available memory in KiB + */ + public long getBalloonSize() { + VmBalloonInfo balloonInfo = vmStatistics.getVmBalloonInfo(); + if (!balloonEnabled || balloonInfo == null) { + return getMemSizeMb() * 1024L; + } + else { + return balloonInfo.getCurrentMemory(); + } + } + public String getOvfVersion() { return vmStatic.getOvfVersion(); } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java index f3ee78e..3190af0 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java @@ -22,6 +22,7 @@ public abstract class AbstractStatisticalQuery<R extends BaseResource, E> { protected static final long Mb = 1024 * 1024L; + protected static final long Kb = 1024L; protected static final BigDecimal CENT = new BigDecimal(100); protected static final StatisticType GAUGE = StatisticType.GAUGE; protected static final StatisticType COUNTER = StatisticType.COUNTER; diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/VmStatisticalQuery.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/VmStatisticalQuery.java index b9da037..b53bf42 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/VmStatisticalQuery.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/VmStatisticalQuery.java @@ -27,7 +27,7 @@ public List<Statistic> getStatistics(org.ovirt.engine.core.common.businessentities.VM entity) { VmStatistics s = entity.getStatisticsData(); long mem = entity.getMemSizeMb() * Mb; - long memUsedByCent = s.getusage_mem_percent()==null ? 0 : mem * s.getusage_mem_percent(); + long memUsedByCent = s.getusage_mem_percent()==null ? 0 : Kb * entity.getBalloonSize() * s.getusage_mem_percent(); Double zero = 0.0; Double cpuUser = s.getcpu_user()==null ? zero : s.getcpu_user(); Double cpuSys = s.getcpu_sys()==null ? zero : s.getcpu_sys(); -- To view, visit http://gerrit.ovirt.org/19618 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If99f073c34ea6a5ba3743e431fc2b03719dd3f48 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Sivák <msi...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches