all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-manager] fixes #3066: resourcestore: add vm hostcpu/hostmem fields
@ 2020-10-23 14:50 Alexandre Derumier
  2021-02-06 14:19 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Derumier @ 2020-10-23 14:50 UTC (permalink / raw)
  To: pve-devel

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@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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH pve-manager] fixes #3066: resourcestore: add vm hostcpu/hostmem fields
  2020-10-23 14:50 [pve-devel] [PATCH pve-manager] fixes #3066: resourcestore: add vm hostcpu/hostmem fields Alexandre Derumier
@ 2021-02-06 14:19 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-02-06 14:19 UTC (permalink / raw)
  To: Proxmox VE development discussion, Alexandre Derumier

On 23.10.20 16:50, Alexandre Derumier wrote:
> 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@odiso.com>
> ---
>  www/manager6/Utils.js              | 101 +++++++++++++++++++++++++++++
>  www/manager6/data/ResourceStore.js |  21 +++++-
>  2 files changed, 121 insertions(+), 1 deletion(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-06 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23 14:50 [pve-devel] [PATCH pve-manager] fixes #3066: resourcestore: add vm hostcpu/hostmem fields Alexandre Derumier
2021-02-06 14:19 ` [pve-devel] applied: " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal