mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	CLOUDSTACK-9665 List hosts api dose not report correct cpu and memory usage.
This commit is contained in:
		
							parent
							
								
									701146ff28
								
							
						
					
					
						commit
						09de5e0b51
					
				| @ -107,6 +107,15 @@ public class HostForMigrationResponse extends BaseResponse { | ||||
|     @Param(description = "the amount of the host's CPU after applying the cpu.overprovisioning.factor ") | ||||
|     private String cpuWithOverprovisioning; | ||||
| 
 | ||||
|     @Deprecated | ||||
|     @SerializedName("memorytotal") | ||||
|     @Param(description = "the memory total of the host, this parameter is deprecated use memorywithoverprovisioning") | ||||
|     private Long memoryTotal; | ||||
| 
 | ||||
|     @SerializedName("memorywithoverprovisioning") | ||||
|     @Param(description = "the amount of the host's memory after applying the mem.overprovisioning.factor ") | ||||
|     private String memWithOverprovisioning; | ||||
| 
 | ||||
|     @SerializedName("averageload") | ||||
|     @Param(description = "the cpu average load on the host") | ||||
|     private Long averageLoad; | ||||
| @ -119,13 +128,9 @@ public class HostForMigrationResponse extends BaseResponse { | ||||
|     @Param(description = "the outgoing network traffic on the host") | ||||
|     private Long networkKbsWrite; | ||||
| 
 | ||||
|     @SerializedName("memorytotal") | ||||
|     @Param(description = "the memory total of the host") | ||||
|     private Long memoryTotal; | ||||
| 
 | ||||
|     @SerializedName("memoryallocated") | ||||
|     @Param(description = "the amount of the host's memory currently allocated") | ||||
|     private Long memoryAllocated; | ||||
|     private String memoryAllocated; | ||||
| 
 | ||||
|     @SerializedName("memoryused") | ||||
|     @Param(description = "the amount of the host's memory currently used") | ||||
| @ -305,11 +310,7 @@ public class HostForMigrationResponse extends BaseResponse { | ||||
|         this.networkKbsWrite = networkKbsWrite; | ||||
|     } | ||||
| 
 | ||||
|     public void setMemoryTotal(Long memoryTotal) { | ||||
|         this.memoryTotal = memoryTotal; | ||||
|     } | ||||
| 
 | ||||
|     public void setMemoryAllocated(Long memoryAllocated) { | ||||
|     public void setMemoryAllocated(String memoryAllocated) { | ||||
|         this.memoryAllocated = memoryAllocated; | ||||
|     } | ||||
| 
 | ||||
| @ -401,6 +402,10 @@ public class HostForMigrationResponse extends BaseResponse { | ||||
|         this.cpuWithOverprovisioning = cpuWithOverprovisioning; | ||||
|     } | ||||
| 
 | ||||
|     public void setMemWithOverprovisioning(String memWithOverprovisioning){ | ||||
|         this.memWithOverprovisioning=memWithOverprovisioning; | ||||
|     } | ||||
| 
 | ||||
|     public void setHypervisorVersion(String hypervisorVersion) { | ||||
|         this.hypervisorVersion = hypervisorVersion; | ||||
|     } | ||||
| @ -408,4 +413,8 @@ public class HostForMigrationResponse extends BaseResponse { | ||||
|     public void setHaHost(Boolean haHost) { | ||||
|         this.haHost = haHost; | ||||
|     } | ||||
| 
 | ||||
|     public void setMemoryTotal(Long memoryTotal) { | ||||
|         this.memoryTotal = memoryTotal; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -125,13 +125,18 @@ public class HostResponse extends BaseResponse { | ||||
|     @Param(description = "the outgoing network traffic on the host") | ||||
|     private Long networkKbsWrite; | ||||
| 
 | ||||
|     @Deprecated | ||||
|     @SerializedName("memorytotal") | ||||
|     @Param(description = "the memory total of the host") | ||||
|     @Param(description = "the memory total of the host, this parameter is deprecated use memorywithoverprovisioning") | ||||
|     private Long memoryTotal; | ||||
| 
 | ||||
|     @SerializedName("memorywithoverprovisioning") | ||||
|     @Param(description = "the amount of the host's memory after applying the mem.overprovisioning.factor") | ||||
|     private String memWithOverprovisioning; | ||||
| 
 | ||||
|     @SerializedName("memoryallocated") | ||||
|     @Param(description = "the amount of the host's memory currently allocated") | ||||
|     private Long memoryAllocated; | ||||
|     private long memoryAllocated; | ||||
| 
 | ||||
|     @SerializedName("memoryused") | ||||
|     @Param(description = "the amount of the host's memory currently used") | ||||
| @ -328,11 +333,11 @@ public class HostResponse extends BaseResponse { | ||||
|         this.networkKbsWrite = networkKbsWrite; | ||||
|     } | ||||
| 
 | ||||
|     public void setMemoryTotal(Long memoryTotal) { | ||||
|         this.memoryTotal = memoryTotal; | ||||
|     public void setMemWithOverprovisioning(String memWithOverprovisioning){ | ||||
|         this.memWithOverprovisioning=memWithOverprovisioning; | ||||
|     } | ||||
| 
 | ||||
|     public void setMemoryAllocated(Long memoryAllocated) { | ||||
|     public void setMemoryAllocated(long memoryAllocated) { | ||||
|         this.memoryAllocated = memoryAllocated; | ||||
|     } | ||||
| 
 | ||||
| @ -458,6 +463,9 @@ public class HostResponse extends BaseResponse { | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public void setMemoryTotal(Long memoryTotal) { | ||||
|         this.memoryTotal = memoryTotal; | ||||
|     } | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
| @ -542,7 +550,7 @@ public class HostResponse extends BaseResponse { | ||||
|         return memoryTotal; | ||||
|     } | ||||
| 
 | ||||
|     public Long getMemoryAllocated() { | ||||
|     public long getMemoryAllocated() { | ||||
|         return memoryAllocated; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -289,7 +289,6 @@ import com.cloud.user.dao.UserDao; | ||||
| import com.cloud.user.dao.UserStatisticsDao; | ||||
| import com.cloud.uservm.UserVm; | ||||
| import com.cloud.utils.EnumUtils; | ||||
| import com.cloud.utils.NumbersUtil; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.vm.ConsoleProxyVO; | ||||
| import com.cloud.vm.DomainRouterVO; | ||||
| @ -1275,10 +1274,14 @@ public class ApiDBUtils { | ||||
|         return s_networkModel.getDedicatedNetworkDomain(networkId); | ||||
|     } | ||||
| 
 | ||||
|     public static float getCpuOverprovisioningFactor() { | ||||
|         String opFactor = s_configDao.getValue(CapacityManager.CpuOverprovisioningFactorCK); | ||||
|         float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1); | ||||
|         return cpuOverprovisioningFactor; | ||||
|     public static float getCpuOverprovisioningFactor(long clusterId) { | ||||
|         float opFactor = CapacityManager.CpuOverprovisioningFactor.valueIn(clusterId); | ||||
|         return opFactor; | ||||
|     } | ||||
| 
 | ||||
|     public static float getMemOverprovisioningFactor(long clusterId) { | ||||
|         float opFactor = CapacityManager.MemOverprovisioningFactor.valueIn(clusterId); | ||||
|         return opFactor; | ||||
|     } | ||||
| 
 | ||||
|     public static boolean isExtractionDisabled() { | ||||
|  | ||||
| @ -154,8 +154,10 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements | ||||
|                 Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity(); | ||||
|                 Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity(); | ||||
| 
 | ||||
|                 hostResponse.setMemoryTotal(mem); | ||||
|                 Float totalMemorywithOverprovisioning=new Float((host.getTotalMemory()*ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId()))); | ||||
|                 hostResponse.setMemWithOverprovisioning(totalMemorywithOverprovisioning.toString()); | ||||
|                 hostResponse.setMemoryAllocated(mem); | ||||
|                 hostResponse.setMemoryTotal(host.getTotalMemory()); | ||||
| 
 | ||||
|                 String hostTags = host.getTag(); | ||||
|                 hostResponse.setHostTags(host.getTag()); | ||||
| @ -173,10 +175,10 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements | ||||
| 
 | ||||
|                 hostResponse.setHypervisorVersion(host.getHypervisorVersion()); | ||||
| 
 | ||||
|                 String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%"; | ||||
|                 Float cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId())); | ||||
|                 String cpuAlloc = decimalFormat.format(((float)cpu / cpuWithOverprovisioning * 100f)) + "%"; | ||||
|                 hostResponse.setCpuAllocated(cpuAlloc); | ||||
|                 String cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor()).toString(); | ||||
|                 hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning); | ||||
|                 hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString()); | ||||
|             } | ||||
| 
 | ||||
|             if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) { | ||||
| @ -297,8 +299,10 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements | ||||
|                 Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity(); | ||||
|                 Long cpu = host.getCpuReservedCapacity() + host.getCpuReservedCapacity(); | ||||
| 
 | ||||
|                 hostResponse.setMemoryAllocated(mem); | ||||
|                 hostResponse.setMemoryTotal(host.getTotalMemory()); | ||||
|                 hostResponse.setMemoryTotal(mem); | ||||
|                 Float memWithOverprovisioning =new Float((host.getTotalMemory()*ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId()))); | ||||
|                 hostResponse.setMemWithOverprovisioning(memWithOverprovisioning.toString()); | ||||
|                 hostResponse.setMemoryAllocated(decimalFormat.format((float)mem/ memWithOverprovisioning*100f).toString()+"%"); | ||||
| 
 | ||||
|                 String hostTags = host.getTag(); | ||||
|                 hostResponse.setHostTags(host.getTag()); | ||||
| @ -316,10 +320,10 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements | ||||
| 
 | ||||
|                 hostResponse.setHypervisorVersion(host.getHypervisorVersion()); | ||||
| 
 | ||||
|                 String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%"; | ||||
|                 Float cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId())); | ||||
|                 String cpuAlloc = decimalFormat.format(((float)cpu / cpuWithOverprovisioning * 100f)).toString() + "%"; | ||||
|                 hostResponse.setCpuAllocated(cpuAlloc); | ||||
|                 String cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor()).toString(); | ||||
|                 hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning); | ||||
|                 hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString()); | ||||
|             } | ||||
| 
 | ||||
|             if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user