From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E939A62123 for ; Fri, 23 Oct 2020 16:51:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D814C293AA for ; Fri, 23 Oct 2020 16:51:00 +0200 (CEST) Received: from kvmformation1.odiso.net (globalOdiso.M6Lille.odiso.net [89.248.211.242]) by firstgate.proxmox.com (Proxmox) with ESMTP id 43D6C293A2 for ; Fri, 23 Oct 2020 16:51:00 +0200 (CEST) Received: by kvmformation1.odiso.net (Postfix, from userid 0) id 160F7A0BD1; Fri, 23 Oct 2020 16:50:52 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Fri, 23 Oct 2020 16:50:50 +0200 Message-Id: <20201023145050.952409-1-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.290 Adjusted score from AWL reputation of From: address HEADER_FROM_DIFFERENT_DOMAINS 0.25 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods KHOP_HELO_FCRDNS 0.275 Relay HELO differs from its IP's reverse DNS NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH pve-manager] fixes #3066: resourcestore: add vm hostcpu/hostmem fields X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Oct 2020 14:51:31 -0000 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 --- 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