From 38afe61d364a7035df19f00a786c5788a55fb138 Mon Sep 17 00:00:00 2001 From: Ciro Scognamiglio Date: Thu, 24 Oct 2013 17:06:56 +0200 Subject: [PATCH] slicestat plugin (working) on the resource view --- plugins/slicestat/__init__.py | 5 +- plugins/slicestat/static/css/slicestat.css | 6 +++ plugins/slicestat/static/js/slicestat.js | 53 ++-------------------- plugins/slicestat/templates/slicestat.html | 3 +- portal/resourceview.py | 3 ++ 5 files changed, 16 insertions(+), 54 deletions(-) diff --git a/plugins/slicestat/__init__.py b/plugins/slicestat/__init__.py index 14cfdad8..7186b761 100644 --- a/plugins/slicestat/__init__.py +++ b/plugins/slicestat/__init__.py @@ -12,8 +12,9 @@ class Slicestat(Plugin): def requirements (self): reqs = { 'js_files' : [ - 'js/date.js', - 'js/slicestat.js' + + 'js/slicestat.js', + ], 'css_files': [ 'css/slicestat.css', diff --git a/plugins/slicestat/static/css/slicestat.css b/plugins/slicestat/static/css/slicestat.css index e69de29b..9962c83b 100644 --- a/plugins/slicestat/static/css/slicestat.css +++ b/plugins/slicestat/static/css/slicestat.css @@ -0,0 +1,6 @@ +iframe#slicestat_resource { + width:100%; + height:400px; + border:0; + overflow: hidden; +} diff --git a/plugins/slicestat/static/js/slicestat.js b/plugins/slicestat/static/js/slicestat.js index 4c63b849..a68704e9 100644 --- a/plugins/slicestat/static/js/slicestat.js +++ b/plugins/slicestat/static/js/slicestat.js @@ -24,10 +24,7 @@ */ init: function(options, element) { // Call the parent constructor, see FAQ when forgotten - this._super(options, element); - - google.load("visualization", "1.0", {packages:["corechart"]}); - + this._super(options, element); /* Member variables */ @@ -93,52 +90,8 @@ { console.log(record); - var node = record.hostname; - var slice = 'root'; - - google.setOnLoadCallback(function() { - - var options = { - pointSize: 2, - lineWidth: 1, - title: 'Slice '+slice+' last 24 hours', 'width':780, 'height':400, - vAxes: { - 0: {format: '###,##%'}, - 1: {format: '#Kb',} - }, - hAxis: { title: "", format: 'HH:mm'}, - series: { - 0: { type: "line", targetAxisIndex: 0}, - 1: { type: "line", targetAxisIndex: 0}, - 2: { type: "line", targetAxisIndex: 1}, - 3: { type: "line", targetAxisIndex: 1} - } - }; - - var jsonData = $.ajax({ - type: 'POST', - url: "/db/slice", - dataType: "json", - async: false, - data: { period: 'day', resources: 'cpu,pmc_per,asb,arb', slice: slice, node: node }, - success: function(ret) { - var result = []; - var data = new google.visualization.DataTable(); - data.addColumn('datetime', 'Date'); - data.addColumn('number', 'CPU (%)'); - data.addColumn('number', 'MEM (%)'); - data.addColumn('number', 'Traffic Sent (Kb)'); - data.addColumn('number', 'Traffic Received (Kb)'); - $.each(ret, function() { - result.push([new Date(this[0]), this[1], this[2], this[3], this[4]]); - }); - data.addRows(result); - var chart = new google.visualization.LineChart(document.getElementById('graph')); - chart.draw(data, options); - } - }).responseText; - - }); + $('iframe#slicestat_resource').attr('src','http://plestats.planet-lab.eu/node.php?node='+record.hostname); + }, /* INTERNAL FUNCTIONS */ diff --git a/plugins/slicestat/templates/slicestat.html b/plugins/slicestat/templates/slicestat.html index cb9474c8..c97cd9e0 100644 --- a/plugins/slicestat/templates/slicestat.html +++ b/plugins/slicestat/templates/slicestat.html @@ -1,4 +1,3 @@
-

Slicestat

-
+
diff --git a/portal/resourceview.py b/portal/resourceview.py index 04218540..7e08fe82 100644 --- a/portal/resourceview.py +++ b/portal/resourceview.py @@ -16,6 +16,8 @@ class ResourceView(TemplateView): def get_context_data(self, **kwargs): page = Page(self.request) + + page.add_js_files ( [ "js/common.functions.js" ] ) for key, value in kwargs.iteritems(): print "%s = %s" % (key, value) @@ -67,6 +69,7 @@ class ResourceView(TemplateView): resource_stats = Slicestat( title = None, page = page, + stats = 'node', key = 'hrn', query = resource_query ) -- 2.43.0