diff --git a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java index 434cd04778a..1b7147211df 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -78,6 +78,7 @@ public class UserConcentratedAllocator implements PodAllocator { Random _rand = new Random(System.currentTimeMillis()); private int _hoursToSkipStoppedVMs = 24; + private int _hoursToSkipDestroyedVMs = 0; private int _secStorageVmRamSize = 1024; private int _proxyRamSize = 256; @@ -202,15 +203,20 @@ public class UserConcentratedAllocator implements PodAllocator { return true; if(vm.getState() == State.Stopped || vm.getState() == State.Destroyed) { - // for stopped/Destroyed VMs, we will skip counting it if it hasn't been used for a while + // for Stopped/Destroyed VMs, we will skip counting it if it hasn't been used for a while + int _hoursToSkipVMs = _hoursToSkipStoppedVMs; + + if (vm.getState() == State.Destroyed) + _hoursToSkipVMs = _hoursToSkipDestroyedVMs; long millisecondsSinceLastUpdate = DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime(); - if(millisecondsSinceLastUpdate > _hoursToSkipStoppedVMs*3600000L) { + if(millisecondsSinceLastUpdate > _hoursToSkipVMs*3600000L) { if(s_logger.isDebugEnabled()) - s_logger.debug("Skip counting vm " + vm.getInstanceName() + " in capacity allocation as it has been stopped for " + millisecondsSinceLastUpdate/60000 + " minutes"); + s_logger.debug("Skip counting " + vm.getState().toString() + " vm " + vm.getInstanceName() + " in capacity allocation as it has been " + vm.getState().toString().toLowerCase() + " for " + millisecondsSinceLastUpdate/60000 + " minutes"); return true; } } + return false; } @@ -308,8 +314,10 @@ public class UserConcentratedAllocator implements PodAllocator { _name = name; Map configs = _configDao.getConfiguration("management-server", params); - String value = configs.get("capacity.skipcounting.hours"); - _hoursToSkipStoppedVMs = NumbersUtil.parseInt(value, 24); + String stoppedValue = configs.get("capacity.skipcounting.hours"); + String destroyedValue = configs.get("capacity.skipcounting.destroyed.hours"); + _hoursToSkipStoppedVMs = NumbersUtil.parseInt(stoppedValue, 24); + _hoursToSkipDestroyedVMs = NumbersUtil.parseInt(destroyedValue, 0); // TODO this is not good, there should be one place to get these values _secStorageVmRamSize = NumbersUtil.parseInt(configs.get("secstorage.vm.ram.size"), 256); diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 60f6ee24e15..5ef77ccc9c3 100644 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -61,7 +61,8 @@ public enum Config { // Usage CapacityCheckPeriod("Usage", ManagementServer.class, Integer.class, "capacity.check.period", "300000", "The interval in milliseconds between capacity checks", null), - CapacitySkipCountingHours("Usage", ManagementServer.class, Integer.class, "capacity.skipcounting.hours", "24", "The interval in hours since VM has stopped to skip counting its allocated CPU/Memory capacity", null), + CapacitySkipCountingHours("Usage", ManagementServer.class, Integer.class, "capacity.skipcounting.hours", "24", "The interval in hours since VM has stopped to skip counting its allocated CPU/Memory capacity. Applies to vms in Stopped state", null), + CapacitySkipCountingDestroyedHours("Usage", ManagementServer.class, Integer.class, "capacity.skipcounting.destroyed.hours", "0", "The interval in hours since VM has stopped to skip counting its allocated CPU/Memory capacity. Applies to vms in Destroyed state", null), StorageAllocatedCapacityThreshold("Usage", ManagementServer.class, Float.class, "storage.allocated.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of allocated storage utilization above which alerts will be sent about low storage available.", null), StorageCapacityThreshold("Usage", ManagementServer.class, Float.class, "storage.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available.", null), CPUCapacityThreshold("Usage", ManagementServer.class, Float.class, "cpu.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which alerts will be sent about low cpu available.", null),