From 5c37238042a01cfebcec28b062410ade0210129f Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 18 Sep 2015 13:59:32 +0530 Subject: [PATCH] metrics: cluster view table model/api wip Signed-off-by: Rohit Yadav --- ui/scripts/metrics.js | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/ui/scripts/metrics.js b/ui/scripts/metrics.js index 58ddc4bd7e2..874a55ae8f2 100644 --- a/ui/scripts/metrics.js +++ b/ui/scripts/metrics.js @@ -54,7 +54,7 @@ hosts: { label: 'label.hosts' }, - cpuavg: { + cpuused: { label: 'Avg CPU Used' }, cpumaxdev: { @@ -66,7 +66,7 @@ cputotal: { label: 'Total CPU Ghz' }, - memavg: { + memused: { label: 'Avg Memory Used' }, memmaxdev: { @@ -80,8 +80,6 @@ } }, dataProvider: function(args) { - console.log(args); - var data = {}; listViewDataProvider(args, data); $.ajax({ @@ -89,7 +87,41 @@ data: data, success: function(json) { var items = json.listclustersresponse.cluster; - console.log(items); + $.each(items, function(idx, cluster) { + $.ajax({ + url: createURL('listHosts'), + data: {clusterid: cluster.id}, + success: function(json) { + items[idx].hosts = json.listhostsresponse.count; + items[idx].cpuused = 0.0; + items[idx].cpumaxdev = 0.0; + items[idx].cpuallocated = 0.0; + items[idx].cputotal = 0.0; + items[idx].memused = 0.0; + items[idx].memmaxdev = 0.0; + items[idx].memallocated = 0.0; + items[idx].memtotal = 0.0; + var maxCpuUsed = 0.0; + $.each(json.listhostsresponse.host, function(i, host) { + if (host.hasOwnProperty('cpuused')) { + items[idx].cpuused += host.cpuused; + if (host.cpuused > maxCpuUsed) { + maxCpuUsed = host.cpuused; + } + } + + if (host.hasOwnProperty('cpuallocated')) { + items[idx].cpuallocated += parseFloat(host.cpuallocated.replace('%', '')); + } + + }); + + items[idx].cpuused = 100.0 * items[idx].cpuused / items[idx].hosts; + items[idx].cpuallocated = (items[idx].cpuallocated / items[idx].hosts).toFixed(2); + }, + async: false + }); + }); args.response.success({ data: items });