[pve-devel] [PATCH pve-manager] fixes #3066: resourcestore: add vm hostcpu/hostmem fields
Alexandre Derumier
aderumier at odiso.com
Fri Oct 23 16:50:50 CEST 2020
This add new fields with cpu/mem percent usage of vms,
relative to host maxcpu/maxmem.
Currently, we can't sort easily most consumming vm on a host.
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
www/manager6/Utils.js | 101 +++++++++++++++++++++++++++++
www/manager6/data/ResourceStore.js | 21 +++++-
2 files changed, 121 insertions(+), 1 deletion(-)
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index bf9ceda9..5eac0d47 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -891,6 +891,56 @@ Ext.define('PVE.Utils', { utilities: {
return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
},
+ calculate_hostcpu: function(data) {
+
+ if (!(data.uptime && Ext.isNumeric(data.cpu))) {
+ return -1;
+ }
+
+ if (data.type !== 'qemu' && data.type !== 'lxc') {
+ return -1;
+ }
+
+ var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
+ var node = PVE.data.ResourceStore.getAt(index);
+ if (!Ext.isDefined(node) || node === null) {
+ return -1;
+ }
+ var maxcpu = node.data.maxcpu || 1;
+
+ if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
+ return -1;
+ }
+
+ return ((data.cpu/maxcpu) * data.maxcpu);
+ },
+
+ render_hostcpu: function(value, metaData, record, rowIndex, colIndex, store) {
+
+ if (!(record.data.uptime && Ext.isNumeric(record.data.cpu))) {
+ return '';
+ }
+
+ if (record.data.type !== 'qemu' && record.data.type !== 'lxc') {
+ return '';
+ }
+
+ var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
+ var node = PVE.data.ResourceStore.getAt(index);
+ if (!Ext.isDefined(node) || node === null) {
+ return '';
+ }
+ var maxcpu = node.data.maxcpu || 1;
+
+ if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
+ return '';
+ }
+
+ var per = (record.data.cpu/maxcpu) * record.data.maxcpu * 100;
+
+ return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
+ },
+
render_size: function(value, metaData, record, rowIndex, colIndex, store) {
if (!Ext.isNumeric(value)) {
@@ -922,6 +972,29 @@ Ext.define('PVE.Utils', { utilities: {
return (data.mem / data.maxmem);
},
+ calculate_hostmem_usage: function(data) {
+
+ if (data.type !== 'qemu' && data.type !== 'lxc') {
+ return -1;
+ }
+
+ var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
+ var node = PVE.data.ResourceStore.getAt(index);
+
+ if (!Ext.isDefined(node) || node === null) {
+ return -1;
+ }
+ var maxmem = node.data.maxmem || 0;
+
+ if (!Ext.isNumeric(data.mem) ||
+ maxmem === 0 ||
+ data.uptime < 1) {
+ return -1;
+ }
+
+ return (data.mem / maxmem);
+ },
+
render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
if (!Ext.isNumeric(value) || value === -1) {
return '';
@@ -941,6 +1014,34 @@ Ext.define('PVE.Utils', { utilities: {
return (value*100).toFixed(1) + " %";
},
+ render_hostmem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
+
+ if (!Ext.isNumeric(record.data.mem) || value === -1) {
+ return '';
+ }
+
+ if (record.data.type !== 'qemu' && record.data.type !== 'lxc') {
+ return '';
+ }
+
+ var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
+ var node = PVE.data.ResourceStore.getAt(index);
+ var maxmem = node.data.maxmem || 0;
+
+ if (record.data.mem > 1 ) {
+ // we got no percentage but bytes
+ var mem = record.data.mem;
+ if (!record.data.uptime ||
+ maxmem === 0 ||
+ !Ext.isNumeric(mem)) {
+ return '';
+ }
+
+ return ((mem*100)/maxmem).toFixed(1) + " %";
+ }
+ return (value*100).toFixed(1) + " %";
+ },
+
render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
var mem = value;
diff --git a/www/manager6/data/ResourceStore.js b/www/manager6/data/ResourceStore.js
index 39928063..4a3e3bdd 100644
--- a/www/manager6/data/ResourceStore.js
+++ b/www/manager6/data/ResourceStore.js
@@ -276,7 +276,26 @@ Ext.define('PVE.data.ResourceStore', {
hidden: true,
sortable: true,
width: 110
- }
+ },
+ hostcpu: {
+ header: gettext('Host CPU usage'),
+ type: 'float',
+ renderer: PVE.Utils.render_hostcpu,
+ calculate: PVE.Utils.calculate_hostcpu,
+ sortType: 'asFloat',
+ sortable: true,
+ width: 100
+ },
+ hostmemuse: {
+ header: gettext('Host Memory usage') + " %",
+ type: 'number',
+ renderer: PVE.Utils.render_hostmem_usage_percent,
+ calculate: PVE.Utils.calculate_hostmem_usage,
+ sortType: 'asFloat',
+ sortable: true,
+ width: 100
+ },
+
};
var fields = [];
--
2.20.1
More information about the pve-devel
mailing list