[pve-devel] [PATCH] resourcestore : add host cpu usage

Alexandre Derumier aderumier at odiso.com
Mon Aug 25 08:39:56 CEST 2014


Currently we can't sort easily vms cpu usage to find which vm use the more host ressource.

This add a new hostcpu, value is vm cpu * vm maxcpus.
(This give us a result like a "top" on host, so 200% = 2 cores 100%).

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/Utils.js              |   11 +++++++++++
 www/manager/data/ResourceStore.js |   22 ++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/www/manager/Utils.js b/www/manager/Utils.js
index f95c180..d5cfc3e 100644
--- a/www/manager/Utils.js
+++ b/www/manager/Utils.js
@@ -787,6 +787,17 @@ Ext.define('PVE.Utils', { statics: {
 	return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
     },
 
+    render_host_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
+
+	if (!(record.data.uptime && Ext.isNumeric(value))) {
+	    return '';
+	}
+
+	var per = value * 100;
+
+	return per.toFixed(1) + '%';
+    },
+
     render_size: function(value, metaData, record, rowIndex, colIndex, store) {
 	/*jslint confusion: true */
 
diff --git a/www/manager/data/ResourceStore.js b/www/manager/data/ResourceStore.js
index 51d0112..cfa5f1d 100644
--- a/www/manager/data/ResourceStore.js
+++ b/www/manager/data/ResourceStore.js
@@ -124,8 +124,26 @@ Ext.define('PVE.data.ResourceStore', {
 		type: 'float',
 		renderer: PVE.Utils.render_cpu,
 		sortable: true,
-		width: 100
+		width: 100,
+	    },
+	    hostcpu: {
+		header: gettext('Host CPU usage'),
+		type: 'float',
+		renderer: PVE.Utils.render_host_cpu,
+		hidden: true,
+		sortable: true,
+		width: 100,
+
+		convert: function(value, record) {
+		    var info = record.data;
+		    if (info.cpu) {
+                        if(Ext.isNumeric(info.maxcpu) && (info.maxcpu > 0)){
+				return (info.cpu * info.maxcpu);
+			}
+		    }
+		}
 	    },
+
 	    maxcpu: {
 		header: gettext('maxcpu'),
 		type: 'integer',
@@ -208,7 +226,7 @@ Ext.define('PVE.data.ResourceStore', {
 	    if (!Ext.isDefined(value.convert)) {
 		fields.push({name: key, type: value.type});
 		fieldNames.push(key);
-	    } else if (key === 'text' || key === 'running') { 
+	    } else if (key === 'text' || key === 'running' || key === 'hostcpu') { 
 		fields.push({name: key, type: value.type, convert: value.convert});
 		fieldNames.push(key);
 	    }		
-- 
1.7.10.4




More information about the pve-devel mailing list