From 404fc4a2829a30ab41563f3c3b9ad3d32a9de301 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 6 Jul 2011 17:06:45 +0200 Subject: [PATCH] Add unpriviledged user dashboard. This dashboard is the same, except it doesnt contain user/group/hosts references, supposing the default user don't have such rights. To fill in the space left by hosts graphs, I have added Total VM memory and cpu graphs. --- .../public/js/plugins/dashboard-tab.js | 24 +- .../public/js/plugins/dashboard-users-tab.js | 298 ++++++++++++++++++ 2 files changed, 304 insertions(+), 18 deletions(-) create mode 100644 src/sunstone/public/js/plugins/dashboard-users-tab.js diff --git a/src/sunstone/public/js/plugins/dashboard-tab.js b/src/sunstone/public/js/plugins/dashboard-tab.js index ac5b375c36..db2c448a28 100644 --- a/src/sunstone/public/js/plugins/dashboard-tab.js +++ b/src/sunstone/public/js/plugins/dashboard-tab.js @@ -15,7 +15,7 @@ /* -------------------------------------------------------------------------- */ var HISTORY_LENGTH=40; -var GRAPH_AUTOREFRESH_INTERVAL=100000; //100 secs +var GRAPH_AUTOREFRESH_INTERVAL=60000; //60 secs var graph1 = { title : "graph1", @@ -84,8 +84,8 @@ var dashboard_tab_content = \ \ \ - Users\ - \ + Users\ + \ \ \ \ @@ -104,10 +104,9 @@ var dashboard_tab_content = Group
\ VM Template
\ VM Instance
\ + Virtual Network
\ Image
\ User
\ - \ - \ \ \ \ @@ -117,7 +116,7 @@ var dashboard_tab_content =
\

Sunstone documentation

\ \ @@ -209,23 +208,15 @@ function plot_global_graph(data,info){ function quickstart_setup(){ - $('#quickstart').button("disable"); - $('#quickstart_form input').click(function(){ - $('#quickstart').val($(this).val()); - $('#quickstart').button("enable"); - }); - - $('#quickstart').click(function(){ Sunstone.runAction($(this).val()); - return false; }); } function graph_autorefresh(){ setInterval(function(){ refresh_graphs(); - },GRAPH_AUTOREFRESH_INTERVAL); + },GRAPH_AUTOREFRESH_INTERVAL+someTime(); } @@ -246,9 +237,6 @@ $(document).ready(function(){ }); emptyDashboard(); - if (uid!=0) { - $("td.oneadmin").hide(); - } quickstart_setup(); diff --git a/src/sunstone/public/js/plugins/dashboard-users-tab.js b/src/sunstone/public/js/plugins/dashboard-users-tab.js new file mode 100644 index 0000000000..f1306f9514 --- /dev/null +++ b/src/sunstone/public/js/plugins/dashboard-users-tab.js @@ -0,0 +1,298 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +var HISTORY_LENGTH=40; +var GRAPH_AUTOREFRESH_INTERVAL=60000; //60 secs + +var graph1 = { + title : "graph1", + monitor_resources : "total,active,error", + history_length : HISTORY_LENGTH +}; + +var graph2 = { + title : "graph2", + monitor_resources : "cpu", + history_length : HISTORY_LENGTH +}; + +var graph3 = { + title : "graph3", + monitor_resources : "memory", + history_length : HISTORY_LENGTH +}; + +var graph4 = { + title : "graph4", + monitor_resources : "net_tx,net_rx", + history_length : HISTORY_LENGTH +}; + +var dashboard_tab_content = +'\ +\ +\ +\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
\ +
\ +

Summary of resources

\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
VM Templates (total/public)
VM Instances (total/running/failed)
Virtual Networks (total/public)
Images (total/public)
\ +\ +
\ +
\ +
\ +
\ +

Quickstart

\ +
\ +
\ + \ + VM Template
\ + VM Instance
\ + Virtual Network
\ + Image
\ +
\ +
\ +
\ +
\ +

Sunstone documentation

\ + \ +
\ +
\ +
\ +\ + \ + \ + \ +
\ +
\ +

Historical monitoring information

\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
Total VM count
'+spinner+'
Total VM CPU
'+spinner+'
Total VM Memory
'+spinner+'
VM Network stats
'+spinner+'
\ +
\ +
\ +
\ +
'; + +var dashboard_tab = { + title: 'Dashboard', + content: dashboard_tab_content, + condition : True +} + +Sunstone.addMainTab('dashboard_tab',dashboard_tab); + +function plot_global_graph(data,info){ + var id = info.title; + var labels_arr = info.monitor_resources.split(','); + var serie; + var series = []; + var width = ($(window).width()-129)*45/100; + + $('#'+id).html('
'); + + for (var i = 0; i< labels_arr.length; i++) { + serie = { + label: labels_arr[i], + data: data[i] + }; + series.push(serie); + }; + + var options = { + legend : { + show : true, + noColumns: labels_arr.length, + container: $('#'+id+'_legend') + }, + xaxis : { + mode: "time", + timeformat: "%h:%M" + }, + yaxis : { labelWidth: 40 } + } + + switch (id){ + case "graph4": + options["yaxis"]["tickFormatter"] = function(val,axis) { + return humanize_size(val); + } + } + + $.plot($('#'+id+'_graph'),series,options); +} + +function quickstart_setup(){ + + $('#quickstart_form input').click(function(){ + Sunstone.runAction($(this).val()); + }); +} + +function graph_autorefresh(){ + setInterval(function(){ + refresh_graphs(); + },GRAPH_AUTOREFRESH_INTERVAL+someTime()); + +} + +function refresh_graphs(){ + Sunstone.runAction("VM.monitor_all", graph1); + Sunstone.runAction("VM.monitor_all", graph2); + Sunstone.runAction("VM.monitor_all", graph3); + Sunstone.runAction("VM.monitor_all", graph4); +} + +$(document).ready(function(){ + //Dashboard link listener + $("#dashboard_table h3 a").live("click", function (){ + var tab = $(this).attr('href'); + showTab(tab); + return false; + }); + + emptyDashboard(); + + quickstart_setup(); + + refresh_graphs(); + graph_autorefresh(); + +}); + +//puts the dashboard values into "retrieving" +function emptyDashboard(){ + $("#dashboard_tab .value_td span").html(spinner); +} + + +function updateDashboard(what,json_info){ + var db = $('#dashboard_tab'); + switch (what){ + case "hosts": + var total_hosts=json_info.length; + var active_hosts=0; + $.each(json_info,function(){ + if (parseInt(this.HOST.STATE) < 3){ + active_hosts++;} + }); + $('#total_hosts',db).html(total_hosts+' / '); + $('#active_hosts',db).html(active_hosts); + break; + case "groups": + var total_groups=json_info.length; + $('#total_groups',db).html(total_groups); + break; + case "vms": + var total_vms=json_info.length; + var running_vms=0; + failed_vms=0; + $.each(json_info,function(){ + vm_state = parseInt(this.VM.STATE); + if (vm_state == 3){ + running_vms++; + } + else if (vm_state == 7) { + failed_vms++; + } + }); + $('#total_vms',db).html(total_vms+' / '); + $('#running_vms',db).html(running_vms+' / '); + $('#failed_vms',db).html(failed_vms); + break; + case "vnets": + var public_vnets=0; + var total_vnets=json_info.length; + $.each(json_info,function(){ + if (parseInt(this.VNET.PUBLIC)){ + public_vnets++;} + }); + $('#total_vnets',db).html(total_vnets+' / '); + $('#public_vnets',db).html(public_vnets); + break; + case "users": + var total_users=json_info.length; + $('#total_users',db).html(total_users); + break; + case "images": + var total_images=json_info.length; + var public_images=0; + $.each(json_info,function(){ + if (parseInt(this.IMAGE.PUBLIC)){ + public_images++;} + }); + $('#total_images',db).html(total_images+' / '); + $('#public_images',db).html(public_images); + break; + case "templates": + var total_templates=json_info.length; + var public_templates=0; + $.each(json_info,function(){ + if (parseInt(this.VMTEMPLATE.PUBLIC)){ + public_templates++; + } + }); + $('#total_templates',db).html(total_templates+' / '); + $('#public_templates',db).html(public_templates); + break; + } +} \ No newline at end of file