Repository: cloudstack Updated Branches: refs/heads/master 85d073b54 -> 5c0979fff
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40225350/ui/scripts/metrics.js ---------------------------------------------------------------------- diff --git a/ui/scripts/metrics.js b/ui/scripts/metrics.js index 554aab7..3152af7 100644 --- a/ui/scripts/metrics.js +++ b/ui/scripts/metrics.js @@ -56,15 +56,15 @@ label: 'label.metrics.cpu.usage', collapsible: true, columns: { - cpuusedavg: { + cpuused: { label: 'label.metrics.cpu.used.avg', thresholdcolor: true, thresholds: { - notification: 'cpunotificationthreshold', + notification: 'cputhreshold', disable: 'cpudisablethreshold' } }, - cpumaxdev: { + cpumaxdeviation: { label: 'label.metrics.cpu.max.dev' } } @@ -77,8 +77,8 @@ label: 'label.metrics.allocated', thresholdcolor: true, thresholds: { - notification: 'cpunotificationthreshold', - disable: 'cpudisablethreshold' + notification: 'cpuallocatedthreshold', + disable: 'cpuallocateddisablethreshold' } }, cputotal: { @@ -90,15 +90,15 @@ label: 'label.metrics.memory.usage', collapsible: true, columns: { - memusedavg: { + memoryused: { label: 'label.metrics.memory.used.avg', thresholdcolor: true, thresholds: { - notification: 'memnotificationthreshold', - disable: 'memdisablethreshold' + notification: 'memorythreshold', + disable: 'memorydisablethreshold' } }, - memmaxdev: { + memorymaxdeviation: { label: 'label.metrics.memory.max.dev' } } @@ -107,15 +107,15 @@ label: 'label.metrics.memory.allocated', collapsible: true, columns: { - memallocated: { + memoryallocated: { label: 'label.metrics.allocated', thresholdcolor: true, thresholds: { - notification: 'memnotificationthreshold', - disable: 'memdisablethreshold' + notification: 'memoryallocatedthreshold', + disable: 'memoryallocateddisablethreshold' } }, - memtotal: { + memorytotal: { label: 'label.metrics.memory.total' } } @@ -125,129 +125,11 @@ var data = {}; listViewDataProvider(args, data); $.ajax({ - url: createURL('listZones'), + url: createURL('listZonesMetrics'), data: data, success: function(json) { - var items = json.listzonesresponse.zone; - if (items) { - $.each(items, function(idx, zone) { - items[idx].clusters = 0; - items[idx].clustersUp = 0; - items[idx].hosts = 0; - items[idx].cpuusedavg = 0.0; - items[idx].cpumaxdev = 0.0; - items[idx].cpuallocated = 0.0; - items[idx].cputotal = 0.0; - items[idx].maxCpuUsed = 0.0; - items[idx].memusedavg = 0.0; - items[idx].memmaxdev = 0.0; - items[idx].memallocated = 0.0; - items[idx].memtotal = 0.0; - items[idx].maxMemUsed = 0.0; - - // Threshold color coding - items[idx].cpunotificationthreshold = 75.0; - items[idx].cpudisablethreshold = 95.0; - items[idx].memnotificationthreshold = 75.0; - items[idx].memdisablethreshold = 95.0; - - $.ajax({ - url: createURL('listClusters'), - data: {zoneid: zone.id, pagesize: -1}, - success: function(json) { - if (json && json.listclustersresponse && json.listclustersresponse.cluster && json.listclustersresponse.count) { - items[idx].clusters += parseInt(json.listclustersresponse.count); - $.each(json.listclustersresponse.cluster, function(i, cluster) { - if (cluster.allocationstate == 'Enabled' && cluster.managedstate == 'Managed') { - items[idx].clustersUp += 1; - } - $.ajax({ - url: createURL('listHosts'), - data: {clusterid: cluster.id, type: 'routing', pagesize: -1}, - success: function(json) { - if (json && json.listhostsresponse && json.listhostsresponse.host && json.listhostsresponse.count) { - items[idx].hosts += parseInt(json.listhostsresponse.count); - $.each(json.listhostsresponse.host, function(i, host) { - if (host.hasOwnProperty('cpuused')) { - var hostCpuUsage = parseFloat(host.cpuused); - items[idx].cpuusedavg += hostCpuUsage; - if (hostCpuUsage > items[idx].maxCpuUsed) { - items[idx].maxCpuUsed = hostCpuUsage; - } - } - - if (host.hasOwnProperty('cpuallocated')) { - items[idx].cpuallocated += parseFloat(host.cpuallocated.replace('%', '')); - } - - if (host.hasOwnProperty('memoryused')) { - var hostMemoryUsage = 100.0 * parseFloat(host.memoryused) / parseFloat(host.memorytotal); - items[idx].memusedavg += hostMemoryUsage; - if (hostMemoryUsage > items[idx].maxMemUsed) { - items[idx].maxMemUsed = hostMemoryUsage; - } - } - - if (host.hasOwnProperty('memoryallocated')) { - items[idx].memallocated += parseFloat(100.0 * parseFloat(host.memoryallocated)/parseFloat(host.memorytotal)); - } - }); - } - }, - async: false - }); - }); - } - }, - async: false - }); - - $.ajax({ - url: createURL('listCapacity'), - data: {zoneid: zone.id}, - success: function(json) { - if (json && json.listcapacityresponse && json.listcapacityresponse.capacity) { - $.each(json.listcapacityresponse.capacity, function(i, capacity) { - // CPU - if (capacity.type == 1) { - items[idx].cputotal = parseInt(capacity.capacitytotal)/1000.0; - } - // Memory - if (capacity.type == 0) { - items[idx].memtotal = parseInt(capacity.capacitytotal)/(1024.0*1024.0*1024.0); - } - }); - } - }, - async: false - }); - - if (items[idx].hosts != 0) { - items[idx].cpuusedavg = (items[idx].cpuusedavg / items[idx].hosts); - items[idx].cpumaxdev = (items[idx].maxCpuUsed - items[idx].cpuusedavg); - items[idx].cpuallocated = (items[idx].cpuallocated / items[idx].hosts); - - items[idx].memusedavg = (items[idx].memusedavg / items[idx].hosts); - items[idx].memmaxdev = (items[idx].maxMemUsed - items[idx].memusedavg); - items[idx].memallocated = (items[idx].memallocated / items[idx].hosts); - } - // Format data - items[idx].cpuusedavg = (items[idx].cpuusedavg).toFixed(2) + "%"; - items[idx].cpumaxdev = (items[idx].cpumaxdev).toFixed(2) + "%"; - items[idx].cpuallocated = (items[idx].cpuallocated).toFixed(2) + "%"; - items[idx].cputotal = (items[idx].cputotal).toFixed(2) + " Ghz"; - - items[idx].memusedavg = (items[idx].memusedavg).toFixed(2) + "%"; - items[idx].memmaxdev = (items[idx].memmaxdev).toFixed(2) + "%"; - items[idx].memallocated = (items[idx].memallocated).toFixed(2) + "%"; - items[idx].memtotal = (items[idx].memtotal).toFixed(2) + " GB"; - - items[idx].clusters = items[idx].clustersUp + ' / ' + items[idx].clusters; - items[idx].state = items[idx].allocationstate; - }); - } args.response.success({ - data: items + data: json.listzonesmetricsresponse.zone }); } }); @@ -290,15 +172,15 @@ label: 'label.metrics.cpu.usage', collapsible: true, columns: { - cpuusedavg: { + cpuused: { label: 'label.metrics.cpu.used.avg', thresholdcolor: true, thresholds: { - notification: 'cpunotificationthreshold', + notification: 'cputhreshold', disable: 'cpudisablethreshold' } }, - cpumaxdev: { + cpumaxdeviation: { label: 'label.metrics.cpu.max.dev' } } @@ -311,8 +193,8 @@ label: 'label.metrics.allocated', thresholdcolor: true, thresholds: { - notification: 'cpunotificationthreshold', - disable: 'cpudisablethreshold' + notification: 'cpuallocatedthreshold', + disable: 'cpuallocateddisablethreshold' } }, cputotal: { @@ -324,15 +206,15 @@ label: 'label.metrics.memory.usage', collapsible: true, columns: { - memusedavg: { + memoryused: { label: 'label.metrics.memory.used.avg', thresholdcolor: true, thresholds: { - notification: 'memnotificationthreshold', - disable: 'memdisablethreshold' + notification: 'memorythreshold', + disable: 'memorydisablethreshold' } }, - memmaxdev: { + memorymaxdeviation: { label: 'label.metrics.memory.max.dev' } } @@ -341,15 +223,15 @@ label: 'label.metrics.memory.allocated', collapsible: true, columns: { - memallocated: { + memoryallocated: { label: 'label.metrics.allocated', thresholdcolor: true, thresholds: { - notification: 'memnotificationthreshold', - disable: 'memdisablethreshold' + notification: 'memoryallocatedthreshold', + disable: 'memoryallocateddisablethreshold' } }, - memtotal: { + memorytotal: { label: 'label.metrics.memory.total' } } @@ -372,154 +254,11 @@ } $.ajax({ - url: createURL('listClusters'), + url: createURL('listClustersMetrics'), data: data, success: function(json) { - var items = json.listclustersresponse.cluster; - if (items) { - $.each(items, function(idx, cluster) { - items[idx].hosts = 0; - items[idx].hostsUp = 0; - items[idx].cpuusedavg = 0.0; - items[idx].cpumaxdev = 0.0; - items[idx].cpuallocated = 0.0; - items[idx].cputotal = 0.0; - items[idx].maxCpuUsed = 0; - items[idx].memusedavg = 0.0; - items[idx].memmaxdev = 0.0; - items[idx].memallocated = 0.0; - items[idx].memtotal = 0.0; - items[idx].maxMemUsed = 0.0; - - // Threshold color coding - items[idx].cpunotificationthreshold = 75.0; - items[idx].cpudisablethreshold = 95.0; - items[idx].memnotificationthreshold = 75.0; - items[idx].memdisablethreshold = 95.0; - - $.ajax({ - url: createURL('listConfigurations'), - data: {clusterid: cluster.id, listAll: true}, - success: function(json) { - if (json.listconfigurationsresponse && json.listconfigurationsresponse.configuration) { - $.each(json.listconfigurationsresponse.configuration, function(i, config) { - switch (config.name) { - case 'cluster.cpu.allocated.capacity.disablethreshold': - items[idx].cpudisablethreshold = 100 * parseFloat(config.value); - break; - case 'cluster.cpu.allocated.capacity.notificationthreshold': - items[idx].cpunotificationthreshold = 100 * parseFloat(config.value); - break; - case 'cluster.memory.allocated.capacity.disablethreshold': - items[idx].memdisablethreshold = 100 * parseFloat(config.value); - break; - case 'cluster.memory.allocated.capacity.notificationthreshold': - items[idx].memnotificationthreshold = 100 * parseFloat(config.value); - break; - } - }); - } - }, - async: false - }); - - $.ajax({ - url: createURL('listHosts'), - data: {clusterid: cluster.id, type: 'routing', pagesize: -1}, - success: function(json) { - if (json && json.listhostsresponse && json.listhostsresponse.host && json.listhostsresponse.count) { - items[idx].hosts += parseInt(json.listhostsresponse.count); - $.each(json.listhostsresponse.host, function(i, host) { - if (host.state == 'Up') { - items[idx].hostsUp += 1; - } - if (host.hasOwnProperty('cpuused')) { - var hostCpuUsage = parseFloat(host.cpuused); - items[idx].cpuusedavg += hostCpuUsage; - if (hostCpuUsage > items[idx].maxCpuUsed) { - items[idx].maxCpuUsed = hostCpuUsage; - } - } - - if (host.hasOwnProperty('cpuallocated')) { - items[idx].cpuallocated += parseFloat(host.cpuallocated.replace('%', '')); - } - - if (host.hasOwnProperty('memoryused')) { - var hostMemoryUsage = 100.0 * parseFloat(host.memoryused) / parseFloat(host.memorytotal); - items[idx].memusedavg += hostMemoryUsage; - if (hostMemoryUsage > items[idx].maxMemUsed) { - items[idx].maxMemUsed = hostMemoryUsage; - } - } - - if (host.hasOwnProperty('memoryallocated')) { - items[idx].memallocated += parseFloat(100.0 * parseFloat(host.memoryallocated)/parseFloat(host.memorytotal)); - } - }); - } - }, - async: false - }); - - $.ajax({ - url: createURL('listCapacity'), - data: {clusterid: cluster.id}, - success: function(json) { - if (json && json.listcapacityresponse && json.listcapacityresponse.capacity) { - $.each(json.listcapacityresponse.capacity, function(i, capacity) { - // CPU - if (capacity.type == 1) { - items[idx].cputotal = parseInt(capacity.capacitytotal)/1000.0; - } - // Memory - if (capacity.type == 0) { - items[idx].memtotal = parseInt(capacity.capacitytotal)/(1024.0*1024.0*1024.0); - } - }); - } - }, - async: false - }); - - if (items[idx].hosts != 0) { - items[idx].cpuusedavg = (items[idx].cpuusedavg / items[idx].hosts); - items[idx].cpumaxdev = (items[idx].maxCpuUsed - items[idx].cpuusedavg); - items[idx].cpuallocated = (items[idx].cpuallocated / items[idx].hosts); - - items[idx].memusedavg = (items[idx].memusedavg / items[idx].hosts); - items[idx].memmaxdev = (items[idx].maxMemUsed - items[idx].memusedavg); - items[idx].memallocated = (items[idx].memallocated / items[idx].hosts); - } - - // Format data - items[idx].cpuusedavg = (items[idx].cpuusedavg).toFixed(2) + "%"; - items[idx].cpumaxdev = (items[idx].cpumaxdev).toFixed(2) + "%"; - items[idx].cpuallocated = (items[idx].cpuallocated).toFixed(2) + "%"; - items[idx].cputotal = (items[idx].cputotal).toFixed(2) + " Ghz"; - - items[idx].memusedavg = (items[idx].memusedavg).toFixed(2) + "%"; - items[idx].memmaxdev = (items[idx].memmaxdev).toFixed(2) + "%"; - items[idx].memallocated = (items[idx].memallocated).toFixed(2) + "%"; - items[idx].memtotal = (items[idx].memtotal).toFixed(2) + " GB"; - items[idx].hosts = items[idx].hostsUp + ' / ' + items[idx].hosts; - - items[idx].state = items[idx].allocationstate; - if (items[idx].managedstate == 'Unmanaged') { - items[idx].state = 'Unmanaged'; - } - - if (items[idx].managedstate == 'Managed' && items[idx].allocationstate == 'Enabled') { - items[idx].state = 'Enabled'; - } - - if (items[idx].managedstate == 'Managed' && items[idx].allocationstate == 'Disabled') { - items[idx].state = 'Disabled'; - } - }); - } args.response.success({ - data: items + data: json.listclustersmetricsresponse.cluster }); } }); @@ -560,7 +299,7 @@ }, compact: true }, - outofbandmanagementpowerstate: { + powerstate: { label: 'label.metrics.outofbandmanagementpowerstate', converter: function (str) { // For localization @@ -580,25 +319,25 @@ label: 'label.metrics.cpu.usage', collapsible: true, columns: { - cores: { - label: 'label.metrics.num.cpu.cores' + cpunumber: { + label: 'label.metrics.num.cpu.cores', }, - cputotal: { + cputotalghz: { label: 'label.metrics.cpu.total' }, - cpuusedavg: { + cpuusedghz: { label: 'label.metrics.cpu.used.avg', thresholdcolor: true, thresholds: { - notification: 'cpunotificationthreshold', + notification: 'cputhreshold', disable: 'cpudisablethreshold' } }, - cpuallocated: { + cpuallocatedghz: { label: 'label.metrics.allocated', thresholdcolor: true, thresholds: { - notification: 'cpuallocatednotificationthreshold', + notification: 'cpuallocatedthreshold', disable: 'cpuallocateddisablethreshold' } } @@ -608,23 +347,23 @@ label: 'label.metrics.memory.usage', collapsible: true, columns: { - memtotal: { + memorytotalgb: { label: 'label.metrics.memory.total' }, - memusedavg: { + memoryusedgb: { label: 'label.metrics.memory.used.avg', thresholdcolor: true, thresholds: { - notification: 'memnotificationthreshold', - disable: 'memdisablethreshold' + notification: 'memorythreshold', + disable: 'memorydisablethreshold' } }, - memallocated: { + memoryallocatedgb: { label: 'label.metrics.allocated', thresholdcolor: true, thresholds: { - notification: 'memallocatednotificationthreshold', - disable: 'memallocateddisablethreshold' + notification: 'memoryallocatedthreshold', + disable: 'memoryallocateddisablethreshold' } } } @@ -670,123 +409,11 @@ } $.ajax({ - url: createURL('listHosts'), + url: createURL('listHostsMetrics'), data: data, success: function(json) { - var items = json.listhostsresponse.host; - if (items) { - $.each(items, function(idx, host) { - if (host && host.outofbandmanagement) { - items[idx].outofbandmanagementpowerstate = host.outofbandmanagement.powerstate; - } - items[idx].cores = host.cpunumber; - items[idx].cputotal = (parseFloat(host.cpunumber) * parseFloat(host.cpuspeed) / 1000.0).toFixed(2); - if (host.cpuused) { - items[idx].cpuusedavg = (parseFloat(host.cpuused) * items[idx].cputotal / 100.0).toFixed(2) + ' Ghz'; - } else { - items[idx].cpuusedavg = ''; - } - items[idx].cpuallocated = (parseFloat(host.cpuallocated) * items[idx].cputotal / 100.0).toFixed(2) + ' Ghz'; - items[idx].memtotal = (parseFloat(host.memorytotal)/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB'; - items[idx].memallocated = (parseFloat(host.memoryallocated)/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB'; - if (host.memoryused) { - items[idx].memusedavg = (parseFloat(host.memoryused)/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB'; - } else { - items[idx].memusedavg = ''; - } - if (host.networkkbsread && host.networkkbswrite) { - items[idx].networkread = (parseFloat(host.networkkbsread)/(1024.0*1024.0)).toFixed(2) + ' GB'; - items[idx].networkwrite = (parseFloat(host.networkkbswrite)/(1024.0*1024.0)).toFixed(2) + ' GB'; - } else { - items[idx].networkread = ''; - items[idx].networkwrite = ''; - } - - var cpuOverCommit = 1.0; - var memOverCommit = 1.0; - $.ajax({ - url: createURL('listClusters'), - data: {clusterid: host.clusterid, listAll: true}, - success: function(json) { - if (json.listclustersresponse && json.listclustersresponse.cluster) { - var cluster = json.listclustersresponse.cluster[0]; - cpuOverCommit = parseFloat(cluster.cpuovercommitratio); - memOverCommit = parseFloat(cluster.memoryovercommitratio); - } - }, - async: false - }); - - // Threshold color coding - items[idx].cpunotificationthreshold = 0.75 * parseFloat(items[idx].cputotal); - items[idx].cpudisablethreshold = 0.95 * parseFloat(items[idx].cputotal); - items[idx].cpuallocatednotificationthreshold = 0.75 * cpuOverCommit * parseFloat(items[idx].cputotal); - items[idx].cpuallocateddisablethreshold = 0.95 * cpuOverCommit * parseFloat(items[idx].cputotal); - - items[idx].memnotificationthreshold = 0.75 * parseFloat(items[idx].memtotal); - items[idx].memdisablethreshold = 0.95 * parseFloat(items[idx].memtotal); - items[idx].memallocatednotificationthreshold = 0.75 * memOverCommit * parseFloat(items[idx].memtotal); - items[idx].memallocateddisablethreshold = 0.95 * memOverCommit * parseFloat(items[idx].memtotal); - - $.ajax({ - url: createURL('listConfigurations'), - data: {clusterid: host.clusterid, listAll: true}, - success: function(json) { - if (json.listconfigurationsresponse && json.listconfigurationsresponse.configuration) { - $.each(json.listconfigurationsresponse.configuration, function(i, config) { - switch (config.name) { - case 'cluster.cpu.allocated.capacity.disablethreshold': - items[idx].cpudisablethreshold = parseFloat(config.value) * parseFloat(items[idx].cputotal); - items[idx].cpuallocateddisablethreshold = parseFloat(config.value) * cpuOverCommit * parseFloat(items[idx].cputotal); - break; - case 'cluster.cpu.allocated.capacity.notificationthreshold': - items[idx].cpunotificationthreshold = parseFloat(config.value) * parseFloat(items[idx].cputotal); - items[idx].cpuallocatednotificationthreshold = parseFloat(config.value) * cpuOverCommit * parseFloat(items[idx].cputotal); - break; - case 'cluster.memory.allocated.capacity.disablethreshold': - items[idx].memdisablethreshold = parseFloat(config.value) * parseFloat(items[idx].memtotal); - items[idx].memallocateddisablethreshold = parseFloat(config.value) * memOverCommit * parseFloat(items[idx].memtotal); - break; - case 'cluster.memory.allocated.capacity.notificationthreshold': - items[idx].memnotificationthreshold = parseFloat(config.value) * parseFloat(items[idx].memtotal); - items[idx].memallocatednotificationthreshold = parseFloat(config.value) * memOverCommit * parseFloat(items[idx].memtotal); - break; - } - }); - } - }, - async: false - }); - - - items[idx].cputotal = items[idx].cputotal + ' Ghz (x' + cpuOverCommit + ')'; - items[idx].memtotal = items[idx].memtotal + ' (x' + memOverCommit + ')'; - - items[idx].instances = 0; - items[idx].instancesUp = 0; - $.ajax({ - url: createURL('listVirtualMachines'), - data: {hostid: host.id, listAll: true}, - success: function(json) { - if (json && json.listvirtualmachinesresponse && json.listvirtualmachinesresponse.virtualmachine) { - var vms = json.listvirtualmachinesresponse.virtualmachine; - if (vms) { - $.each(vms, function(_, vm) { - items[idx].instances += 1; - if (vm.state == 'Running') { - items[idx].instancesUp += 1; - } - }); - } - } - }, - async: false - }); - items[idx].instances = items[idx].instancesUp + ' / ' + items[idx].instances; - }); - } args.response.success({ - data: items + data: json.listhostsmetricsresponse.host }); } }); @@ -838,14 +465,14 @@ label: 'label.metrics.cpu.usage', collapsible: true, columns: { - cores: { - label: 'label.metrics.num.cpu.cores' + cpunumber: { + label: 'label.metrics.num.cpu.cores', }, cputotal: { label: 'label.metrics.cpu.total' }, cpuused: { - label: 'label.metrics.cpu.used.avg' + label: 'label.metrics.cpu.used.avg', } } }, @@ -853,7 +480,7 @@ label: 'label.metrics.memory.usage', collapsible: true, columns: { - memallocated: { + memorytotal: { label: 'label.metrics.allocated' } } @@ -874,10 +501,10 @@ label: 'label.metrics.disk.usage', collapsible: true, columns: { - diskread: { + diskioread: { label: 'label.metrics.disk.read' }, - diskwrite: { + diskiowrite: { label: 'label.metrics.disk.write' }, diskiopstotal: { @@ -899,45 +526,11 @@ } $.ajax({ - url: createURL('listVirtualMachines'), + url: createURL('listVirtualMachinesMetrics'), data: data, success: function(json) { - var items = []; - if (json && json.listvirtualmachinesresponse && json.listvirtualmachinesresponse.virtualmachine) { - items = json.listvirtualmachinesresponse.virtualmachine; - $.each(items, function(idx, vm) { - items[idx].cores = vm.cpunumber; - items[idx].cputotal = (parseFloat(vm.cpunumber) * parseFloat(vm.cpuspeed) / 1000.0).toFixed(1) + ' Ghz'; - items[idx].cpuusedavg = vm.cpuused; - items[idx].cpuallocated = vm.cpuallocated; - items[idx].memallocated = (parseFloat(vm.memory)/1024.0).toFixed(2) + ' GB'; - items[idx].networkread = (parseFloat(vm.networkkbsread)/(1024.0)).toFixed(2) + ' MB'; - items[idx].networkwrite = (parseFloat(vm.networkkbswrite)/(1024.0)).toFixed(2) + ' MB'; - items[idx].diskread = (parseFloat(vm.diskkbsread)/(1024.0)).toFixed(2) + ' MB'; - items[idx].diskwrite = (parseFloat(vm.diskkbswrite)/(1024.0)).toFixed(2) + ' MB'; - items[idx].diskiopstotal = parseFloat(vm.diskioread) + parseFloat(vm.diskiowrite); - if (vm.nic && vm.nic.length > 0 && vm.nic[0].ipaddress) { - items[idx].ipaddress = vm.nic[0].ipaddress; - } - - var keys = [{'cpuused': 'cpuusedavg'}, - {'networkkbsread': 'networkread'}, - {'networkkbswrite': 'networkwrite'}, - {'diskkbsread': 'diskread'}, - {'diskkbswrite': 'diskwrite'}, - {'diskioread': 'diskiopstotal'}]; - for (keyIdx in keys) { - var map = keys[keyIdx]; - var key = Object.keys(map)[0]; - var uiKey = map[key]; - if (!vm.hasOwnProperty(key)) { - items[idx][uiKey] = ''; - } - } - }); - } args.response.success({ - data: items + data: json.listvirtualmachinesmetricsresponse.virtualmachine }); } }); @@ -974,22 +567,22 @@ 'Expunging': 'off', 'Migrating': 'warning', 'UploadOp': 'transition', - 'Snapshotting': 'warning' + 'Snapshotting': 'warning', }, compact: true }, vmname: { label: 'label.metrics.vm.name' }, - disksize: { + sizegb: { label: 'label.metrics.disk.size' }, storagetype: { label: 'label.metrics.disk.storagetype' }, - storagepool: { + storage: { label: 'label.metrics.storagepool' - } + }, }, dataProvider: function(args) { var data = {listAll: true}; @@ -1008,25 +601,11 @@ } $.ajax({ - url: createURL('listVolumes'), + url: createURL('listVolumesMetrics'), data: data, success: function(json) { - var items = []; - if (json && json.listvolumesresponse && json.listvolumesresponse.volume) { - items = json.listvolumesresponse.volume; - $.each(items, function(idx, volume) { - items[idx].name = volume.name; - items[idx].state = volume.state; - items[idx].vmname = volume.vmname; - items[idx].disksize = parseFloat(volume.size)/(1024.0*1024.0*1024.0) + ' GB'; - items[idx].storagetype = volume.storagetype.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}) + ' (' + volume.type + ')'; - if (volume.storage) { - items[idx].storagepool = volume.storage; - } - }); - } args.response.success({ - data: items + data: json.listvolumesmetricsresponse.volume }); } }); @@ -1062,7 +641,7 @@ 'ErrorInMaintenance': 'off', 'PrepareForMaintenance': 'transition', 'CancelMaintenance': 'warning', - 'Maintenance': 'warning' + 'Maintenance': 'warning', }, compact: true }, @@ -1078,26 +657,26 @@ label: 'label.metrics.disk', collapsible: true, columns: { - disksizeused: { + disksizeusedgb: { label: 'label.metrics.disk.used', thresholdcolor: true, thresholds: { - notification: 'storagenotificationthreshold', - disable: 'storagedisablethreshold' + notification: 'storageusagethreshold', + disable: 'storageusagedisablethreshold' } }, - disksizetotal: { + disksizetotalgb: { label: 'label.metrics.disk.total' }, - disksizeallocated: { + disksizeallocatedgb: { label: 'label.metrics.disk.allocated', thresholdcolor: true, thresholds: { - notification: 'storageallocatednotificationthreshold', + notification: 'storageallocatedthreshold', disable: 'storageallocateddisablethreshold' } }, - disksizeunallocated: { + disksizeunallocatedgb: { label: 'label.metrics.disk.unallocated' } } @@ -1124,74 +703,11 @@ } $.ajax({ - url: createURL('listStoragePools'), + url: createURL('listStoragePoolsMetrics'), data: data, success: function(json) { - var items = []; - if (json && json.liststoragepoolsresponse && json.liststoragepoolsresponse.storagepool) { - items = json.liststoragepoolsresponse.storagepool; - $.each(items, function(idx, pool) { - items[idx].name = pool.name; - items[idx].state = pool.state; - items[idx].scope = pool.scope; - items[idx].type = pool.type; - items[idx].overprovisionfactor = parseFloat(pool.overprovisionfactor); - if (pool.disksizeused) { - items[idx].disksizeused = (parseFloat(pool.disksizeused)/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB'; - } else { - items[idx].disksizeused = ''; - } - items[idx].disksizetotal = parseFloat(pool.disksizetotal); - items[idx].disksizeallocated = parseFloat(pool.disksizeallocated); - items[idx].disksizeunallocated = (items[idx].overprovisionfactor * items[idx].disksizetotal) - items[idx].disksizeallocated; - - // Format presentation - items[idx].disksizetotal = (items[idx].disksizetotal/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB (x' + items[idx].overprovisionfactor + ')'; - items[idx].disksizeallocated = (items[idx].disksizeallocated/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB'; - items[idx].disksizeunallocated = (items[idx].disksizeunallocated/(1024.0*1024.0*1024.0)).toFixed(2) + ' GB'; - - // Threshold color coding - items[idx].storagenotificationthreshold = 0.75 * parseFloat(items[idx].disksizetotal); - items[idx].storagedisablethreshold = 0.95 * parseFloat(items[idx].disksizetotal); - items[idx].storageallocatednotificationthreshold = 0.75 * parseFloat(items[idx].disksizetotal) * items[idx].overprovisionfactor; - items[idx].storageallocateddisablethreshold = 0.95 * parseFloat(items[idx].disksizetotal) * items[idx].overprovisionfactor; - - - var getThresholds = function(data, items, idx) { - data.listAll = true; - $.ajax({ - url: createURL('listConfigurations'), - data: data, - success: function(json) { - if (json.listconfigurationsresponse && json.listconfigurationsresponse.configuration) { - $.each(json.listconfigurationsresponse.configuration, function(i, config) { - switch (config.name) { - case 'cluster.storage.allocated.capacity.notificationthreshold': - items[idx].storageallocatednotificationthreshold = parseFloat(config.value) * items[idx].overprovisionfactor * parseFloat(items[idx].disksizetotal); - break; - case 'cluster.storage.capacity.notificationthreshold': - items[idx].storagenotificationthreshold = parseFloat(config.value) * parseFloat(items[idx].disksizetotal); - break; - case 'pool.storage.allocated.capacity.disablethreshold': - items[idx].storageallocateddisablethreshold = parseFloat(config.value) * items[idx].overprovisionfactor * parseFloat(items[idx].disksizetotal); - break; - case 'pool.storage.capacity.disablethreshold': - items[idx].storagedisablethreshold = parseFloat(config.value) * parseFloat(items[idx].disksizetotal); - break; - } - }); - } - }, - async: false - }); - }; - // Update global and cluster level thresholds - getThresholds({}, items, idx); - getThresholds({clusterid: pool.clusterid}, items, idx); - }); - } args.response.success({ - data: items + data: json.liststoragepoolsmetricsresponse.storagepool }); } }); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40225350/ui/scripts/system.js ---------------------------------------------------------------------- diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 98403ed..682e0a2 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -225,322 +225,25 @@ // System dashboard dashboard: { dataProvider: function (args) { - var dataFns = { - zoneCount: function (data) { - $.ajax({ - url: createURL('listZones'), - data: { - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }, - success: function (json) { - args.response.success({ - data: { - zoneCount: json.listzonesresponse.count ? json.listzonesresponse.count: 0, - zones: json.listzonesresponse.zone - } - }); - } - }); - dataFns.podCount(); - }, - - podCount: function (data) { - $.ajax({ - url: createURL('listPods'), - data: { - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }, - success: function (json) { - args.response.success({ - data: { - podCount: json.listpodsresponse.count ? json.listpodsresponse.count: 0 - } - }); - } - }); - dataFns.clusterCount(); - }, - - clusterCount: function (data) { - $.ajax({ - url: createURL('listClusters'), - data: { - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }, - success: function (json) { - args.response.success({ - data: { - clusterCount: json.listclustersresponse.count ? json.listclustersresponse.count: 0 - } - }); - } - }); - dataFns.hostCount(); - }, - - hostCount: function (data) { - var data2 = { - type: 'routing', - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }; - $.ajax({ - url: createURL('listHosts'), - data: data2, - success: function (json) { - args.response.success({ - data: { - hostCount: json.listhostsresponse.count ? json.listhostsresponse.count: 0 - } - }); - } - }); - dataFns.primaryStorageCount(); - }, - - primaryStorageCount: function (data) { - var data2 = { - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }; - $.ajax({ - url: createURL('listStoragePools'), - data: data2, - success: function (json) { - args.response.success({ - data: { - primaryStorageCount: json.liststoragepoolsresponse.count ? json.liststoragepoolsresponse.count: 0 - } - }); - } - }); - dataFns.secondaryStorageCount(); - }, - - secondaryStorageCount: function (data) { - var data2 = { - type: 'SecondaryStorage', - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }; - $.ajax({ - url: createURL('listImageStores'), - data: data2, - success: function (json) { - args.response.success({ - data: { - secondaryStorageCount: json.listimagestoresresponse.imagestore ? json.listimagestoresresponse.count: 0 - } - }); - } - }); - dataFns.systemVmCount(); - }, - - systemVmCount: function (data) { - $.ajax({ - url: createURL('listSystemVms'), - data: { - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }, - success: function (json) { - args.response.success({ - data: { - systemVmCount: json.listsystemvmsresponse.count ? json.listsystemvmsresponse.count: 0 - } - }); - } - }); - dataFns.virtualRouterCount(); - }, - - virtualRouterCount: function (data) { - var data2 = { - listAll: true, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }; - $.ajax({ - url: createURL('listRouters'), - data: data2, - success: function (json) { - var total1 = json.listroutersresponse.count ? json.listroutersresponse.count: 0; - var total2 = 0; //reset - - /* - * In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1), - * because in project view, all API calls are appended with projectid=[projectID]. - * Therefore, we only call the second listRouters API(with projectid=-1) in non-project view. - */ - if (cloudStack.context && cloudStack.context.projects == null) { //non-project view - var data3 = { - listAll: true, - projectid: -1, - page: 1, - pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. - }; - $.ajax({ - url: createURL('listRouters'), - data: data3, - async: false, - success: function (json) { - total2 = json.listroutersresponse.count ? json.listroutersresponse.count : 0; - } - }); - } - - args.response.success({ - data: { - virtualRouterCount: (total1 + total2) - } - }); - } - }); - dataFns.capacity(); - }, - - capacity: function (data) { - $.ajax({ - url: createURL('listCapacity'), - success: function (json) { - var capacities = json.listcapacityresponse.capacity; - if(capacities) { - var capacityTotal = function (id, converter) { - var capacity = $.grep(capacities, function (capacity) { - return capacity.type == id; - })[0]; - - var total = capacity ? capacity.capacitytotal: 0; - - if (converter) { - return converter(total); - } - - return total; - }; - - args.response.success({ - data: { - cpuCapacityTotal: capacityTotal(1, cloudStack.converters.convertHz), - memCapacityTotal: capacityTotal(0, cloudStack.converters.convertBytes), - storageCapacityTotal: capacityTotal(2, cloudStack.converters.convertBytes) - } - }); - - } else { - - args.response.success({ - data: { - cpuCapacityTotal: cloudStack.converters.convertHz(0), - memCapacityTotal: cloudStack.converters.convertBytes(0), - storageCapacityTotal: cloudStack.converters.convertBytes(0) - } - }); - - } - } - }); - - dataFns.socketInfo(); - }, - - socketInfo: function (data) { - var socketCount = 0; - - function listHostFunction(hypervisor, pageSizeValue) { - var deferred = $.Deferred(); - var totalHostCount = 0; - var returnedHostCount = 0; - var returnedHostCpusocketsSum = 0; - - var callListHostsWithPage = function(page) { - $.ajax({ - url: createURL('listHosts'), - data: { - type: 'routing', - hypervisor: hypervisor, - page: page, - details: 'min', - pagesize: pageSizeValue - }, - success: function (json) { - if (json.listhostsresponse.count == undefined) { - deferred.resolve(); - return; - } - - totalHostCount = json.listhostsresponse.count; - returnedHostCount += json.listhostsresponse.host.length; - - var items = json.listhostsresponse.host; - for (var i = 0; i < items.length; i++) { - if (items[i].cpusockets != undefined && isNaN(items[i].cpusockets) == false) { - returnedHostCpusocketsSum += items[i].cpusockets; - } - } - - if (returnedHostCount < totalHostCount) { - callListHostsWithPage(++page); - } else { - socketCount += returnedHostCpusocketsSum; - deferred.resolve(); - } - } - }); - } - - callListHostsWithPage(1); - - return deferred; - - } - - $.ajax({ - url: createURL('listConfigurations'), - data: { - name : 'default.page.size' - }, - success: function (json) { - pageSizeValue = json.listconfigurationsresponse.configuration[0].value; - if(!pageSizeValue) { - return; - } - $.ajax({ - url: createURL('listHypervisors'), - success: function (json) { - var deferredArray = []; - - $(json.listhypervisorsresponse.hypervisor).map(function (index, hypervisor) { - deferredArray.push(listHostFunction(hypervisor.name, pageSizeValue)); - }); - - $.when.apply(null, deferredArray).then(function(){ - args.response.success({ - data: { - socketCount: socketCount - } - }); - }); - } - }); - } + $.ajax({ + url: createURL('listInfrastructure'), + success: function (json) { + var response = json.listinfrastructureresponse.infrastructure; + var data = {}; + data.zoneCount = response.zones; + data.podCount = response.pods; + data.clusterCount = response.clusters; + data.hostCount = response.hosts; + data.primaryStorageCount = response.storagepools; + data.secondaryStorageCount = response.imagestores; + data.systemVmCount = response.systemvms; + data.virtualRouterCount = response.routers; + data.socketCount = response.cpusockets; + args.response.success({ + data: data }); - } - }; - - dataFns.zoneCount(); + }); } }, http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40225350/ui/scripts/ui/widgets/listView.js ---------------------------------------------------------------------- diff --git a/ui/scripts/ui/widgets/listView.js b/ui/scripts/ui/widgets/listView.js index e61f43c..fed6194 100644 --- a/ui/scripts/ui/widgets/listView.js +++ b/ui/scripts/ui/widgets/listView.js @@ -1245,12 +1245,11 @@ if (field.thresholdcolor && field.thresholds) { if ((field.thresholds.disable in dataItem) && (field.thresholds.notification in dataItem)) { - var disableThreshold = parseFloat(dataItem[field.thresholds.disable]); - var notificationThreshold = parseFloat(dataItem[field.thresholds.notification]); - var value = parseFloat(content); - if (value >= disableThreshold) { + var disableThreshold = dataItem[field.thresholds.disable]; + var notificationThreshold = dataItem[field.thresholds.notification]; + if (disableThreshold) { $td.addClass('alert-disable-threshold'); - } else if (value >= notificationThreshold) { + } else if (notificationThreshold) { $td.addClass('alert-notification-threshold'); } }
