mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: fix NaN values for external resource metrics (#11302)
CPU and RAM values for external resource metrics was showing NaN values. This fixes the behaviour. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
45edf82efa
commit
524f0d80db
@ -207,8 +207,7 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
||||
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
|
||||
hostResponse.setMemoryAllocated(mem);
|
||||
hostResponse.setMemoryAllocatedBytes(mem);
|
||||
String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%";
|
||||
hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
|
||||
hostResponse.setMemoryAllocatedPercentage(calculateResourceAllocatedPercentage(mem, memWithOverprovisioning));
|
||||
|
||||
String hostTags = host.getTag();
|
||||
hostResponse.setHostTags(hostTags);
|
||||
@ -401,6 +400,9 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
|
||||
}
|
||||
|
||||
private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) {
|
||||
if (resource == 0 || resourceWithOverProvision == 0) {
|
||||
return "0.00%";
|
||||
}
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user