Skip to content

Commit 524f0d8

Browse files
authored
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 <[email protected]>
1 parent 45edf82 commit 524f0d8

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);
@@ -401,6 +400,9 @@ public List<HostJoinVO> findByClusterId(Long clusterId, Host.Type type) {
401400
}
402401

403402
private String calculateResourceAllocatedPercentage(float resource, float resourceWithOverProvision) {
403+
if (resource == 0 || resourceWithOverProvision == 0) {
404+
return "0.00%";
405+
}
404406
DecimalFormat decimalFormat = new DecimalFormat("#.##");
405407
return decimalFormat.format(((float)resource / resourceWithOverProvision * 100.0f)) + "%";
406408
}

0 commit comments

Comments
 (0)