Skip to content

Commit

Permalink
M #~: Fix real cpu & memory bars (OpenNebula#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Betanzos authored and atodorov-storpool committed Jan 7, 2021
1 parent 468752d commit 731b3b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
21 changes: 11 additions & 10 deletions src/sunstone/public/app/tabs/hosts-tab/utils/cpu-bars.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ define(function(require) {
var _html = function(host, hostShareFlag) {
var hostShare = hostShareFlag ? host : host && host.HOST_SHARE;
var hostMonitoring = hostShareFlag ? host : host.MONITORING && host.MONITORING.CAPACITY
var maxCPU = parseInt(hostShare.MAX_CPU||0);
var infoStr;
var allocatedCPUBar
if (hostShare.CPU_USAGE) {
var maxCPU = parseInt(hostShare.MAX_CPU||0);
var allocatedCPU = parseInt(hostShare.CPU_USAGE,10);
if (maxCPU > 0) {
var ratioAllocatedCPU = Math.round((allocatedCPU / maxCPU) * 100);
var ratioAllocatedCPU = Math.round((allocatedCPU / maxCPU) * 100);
infoStr = allocatedCPU + ' / ' + maxCPU + ' (' + ratioAllocatedCPU + '%)';
} else {
} else {
infoStr = "";
}
allocatedCPUBar = ProgressBar.html(allocatedCPU, maxCPU, infoStr);
}
allocatedCPUBar = ProgressBar.html(allocatedCPU, maxCPU, infoStr);
}
var realCPUBar
var realCPUBar
if (hostMonitoring && hostMonitoring.USED_CPU) {
var totalCPU = parseInt(hostShare.TOTAL_CPU||0);
var realCPU = parseInt(hostMonitoring.USED_CPU,10);
if (maxCPU > 0) {
var ratioRealCPU = Math.round((realCPU / maxCPU) * 100);
infoStr = realCPU + ' / ' + maxCPU + ' (' + ratioRealCPU + '%)';
if (totalCPU > 0) {
var ratioRealCPU = Math.round((realCPU / totalCPU) * 100);
infoStr = realCPU + ' / ' + totalCPU + ' (' + ratioRealCPU + '%)';
} else {
infoStr = "";
}
realCPUBar = ProgressBar.html(realCPU, maxCPU, infoStr);
realCPUBar = ProgressBar.html(realCPU, totalCPU, infoStr);
}
return {
real: realCPUBar,
Expand Down
17 changes: 9 additions & 8 deletions src/sunstone/public/app/tabs/hosts-tab/utils/memory-bars.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ define(function(require) {
var _html = function(host, hostShareFlag) {
var hostShare = hostShareFlag ? host : host.HOST_SHARE;
var hostMonitoring = hostShareFlag ? host : host.MONITORING && host.MONITORING.CAPACITY
var maxMem = parseInt(hostShare.MAX_MEM||0);
var infoStr = "";
var allocatedMemBar;
if (hostShare.MEM_USAGE) {
var maxMem = parseInt(hostShare.MAX_MEM||0);
var allocatedMem = parseInt(hostShare.MEM_USAGE);
if (maxMem > 0) {
var ratioAllocatedMem = Math.round((allocatedMem / maxMem) * 100);
infoStr = Humanize.size(allocatedMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioAllocatedMem + '%)';
var ratioAllocatedMem = Math.round((allocatedMem / maxMem) * 100);
infoStr = Humanize.size(allocatedMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioAllocatedMem + '%)';
} else {
infoStr = Humanize.size(allocatedMem) + ' / -';
infoStr = Humanize.size(allocatedMem) + ' / -';
}
allocatedMemBar = ProgressBar.html(allocatedMem, maxMem, infoStr);
}
var realMemBar;
if (hostMonitoring && hostMonitoring.USED_MEMORY) {
var totalMem = parseInt(hostShare.TOTAL_MEM||0);
var realMem = parseInt(hostMonitoring.USED_MEMORY,10);
if (maxMem > 0) {
var ratioRealMem = Math.round((realMem / maxMem) * 100);
infoStr = Humanize.size(realMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioRealMem + '%)';
if (totalMem > 0) {
var ratioRealMem = Math.round((realMem / totalMem) * 100);
infoStr = Humanize.size(realMem) + ' / ' + Humanize.size(totalMem) + ' (' + ratioRealMem + '%)';
} else {
infoStr = Humanize.size(realMem) + ' / -';
}
realMemBar = ProgressBar.html(realMem, maxMem, infoStr);
realMemBar = ProgressBar.html(realMem, totalMem, infoStr);
}
return {
real: realMemBar,
Expand Down

0 comments on commit 731b3b0

Please sign in to comment.