if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
// stats calculation
String cpuUsed = null;
VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
if (vmStats != null) {
float cpuUtil = (float) vmStats.getCPUUtilization();
cpuUsed = decimalFormat.format(cpuUtil) + "%";
userVmResponse.setCpuUsed(cpuUsed);
Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs());
userVmResponse.setNetworkKbsRead(networkKbRead.longValue());
Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs());
userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue());
if ((userVm.getHypervisorType() != null)
&& (userVm.getHypervisorType().equals(HypervisorType.KVM)
|| userVm.getHypervisorType().equals(HypervisorType.XenServer))) { // support KVM and XenServer only util 2013.06.25
Double diskKbsRead = Double.valueOf(vmStats.getDiskReadKBs());
userVmResponse.setDiskKbsRead(diskKbsRead.longValue());
Double diskKbsWrite = Double.valueOf(vmStats.getDiskWriteKBs());
userVmResponse.setDiskKbsWrite(diskKbsWrite.longValue());
Double diskIORead = Double.valueOf(vmStats.getDiskReadIOs());
userVmResponse.setDiskIORead(diskIORead.longValue());
Double diskIOWrite = Double.valueOf(vmStats.getDiskWriteIOs());
userVmResponse.setDiskIOWrite(diskIOWrite.longValue());
}
}
}