Skip to content

Commit 9be8115

Browse files
shwstpprdhslove
authored andcommitted
server: fix NaN values for external resource metrics (apache#11302)
CPU and RAM values for external resource metrics was showing NaN values. This fixes the behaviour. Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 7d9832c commit 9be8115

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ private void setNewHostResponseBase(HostJoinVO host, EnumSet<HostDetails> detail
207207
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
208208
hostResponse.setMemoryAllocated(mem);
209209
hostResponse.setMemoryAllocatedBytes(mem);
210-
String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%";
211-
hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
210+
hostResponse.setMemoryAllocatedPercentage(calculateResourceAllocatedPercentage(mem, memWithOverprovisioning));
212211

213212
String hostTags = host.getTag();
214213
hostResponse.setHostTags(hostTags);
@@ -406,6 +405,9 @@ public List<HostJoinVO> findByClusterId(Long clusterId, Host.Type type) {
406405
}
407406

408407
private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) {
408+
if (resource == 0 || resourceWithOverProvision == 0) {
409+
return "0.00%";
410+
}
409411
DecimalFormat decimalFormat = new DecimalFormat("#.##");
410412
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
411413
}

0 commit comments

Comments
 (0)