feature #3748: Add cpuBars and memoryBars utils

This commit is contained in:
Daniel Molina committed 2015-05-18 16:58:04 +02:00
1 parent ea60c75da3
commit f02b386167
2 files changed
+110

No files matched your search

@@ -0,0 +1,55 @@
define(function(require) {
/*
Generate an Object containing the html for the real and allocated CPU
*/
var ProgressBar = require('utils/progress-bar');
var Humanize = require('utils/humanize')
/*
@param {Object} info Object representing the Host as returned by OpenNebula
@param {Boolean} hostShareFlag if true the info param is the HOST_SHARE element instead of HOSt
*/
var _html = function(host, hostShareFlag) {
var hostShare = hostShareFlag ? host : host.HOST_SHARE;
var maxCPU = parseInt(hostShare.MAX_CPU);
var infoStr;
var allocatedCPUBar
if (hostShare.CPU_USAGE) {
var allocatedCPU = parseInt(hostShare.CPU_USAGE);
if (maxCPU > 0) {
var ratioAllocatedCPU = Math.round((allocatedCPU / maxCPU) * 100);
infoStr = allocatedCPU + ' / ' + maxCPU + ' (' + ratioAllocatedCPU + '%)';
} else {
infoStr = "";
}
allocatedCPUBar = ProgressBar.html(allocatedCPU, maxCPU, infoStr);
}
var realCPUBar
if (hostShare.USED_CPU) {
var realCPU = parseInt(hostShare.USED_CPU);
if (maxCPU > 0) {
var ratioRealCPU = Math.round((realCPU / maxCPU) * 100);
infoStr = realCPU + ' / ' + maxCPU + ' (' + ratioRealCPU + '%)';
} else {
infoStr = "";
}
realCPUBar = ProgressBar.html(realCPU, maxCPU, infoStr);
}
return {
real: realCPUBar,
allocated: allocatedCPUBar
}
}
return {
'html': _html
}
})
@@ -0,0 +1,55 @@
define(function(require) {
/*
Generate an Object containing the html for the real and allocated MEMORY
*/
var ProgressBar = require('utils/progress-bar');
var Humanize = require('utils/humanize')
/*
@param {Object} info Object representing the Host as returned by OpenNebula
@param {Boolean} hostShareFlag if true the info param is the HOST_SHARE element instead of HOSt
*/
var _html = function(host, hostShareFlag) {
var hostShare = hostShareFlag ? host : host.HOST_SHARE;
var maxMem = parseInt(hostShare.MAX_MEM);
var infoStr = "";
var allocatedMemBar;
if (hostShare.MEM_USAGE) {
var allocatedMem = parseInt(hostShare.MEM_USAGE);
if (maxMem > 0) {
var ratioAllocatedMem = Math.round((allocatedMem / maxMem) * 100);
infoStr = Humanize.size(allocatedMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioAllocatedMem + '%)';
} else {
infoStr = Humanize.size(allocatedMem) + ' / -';
}
allocatedMemBar = ProgressBar.html(allocatedMem, maxMem, infoStr);
}
var realMemBar;
if (hostShare.USED_MEM) {
var realMem = parseInt(hostShare.USED_MEM);
if (maxMem > 0) {
var ratioRealMem = Math.round((realMem / maxMem) * 100);
infoStr = Humanize.size(realMem) + ' / ' + Humanize.size(maxMem) + ' (' + ratioRealMem + '%)';
} else {
infoStr = Humanize.size(realMem) + ' / -';
}
realMemBar = ProgressBar.html(realMem, maxMem, infoStr);
}
return {
real: realMemBar,
allocated: allocatedMemBar
}
}
return {
'html': _html
}
})