[pve-devel] r5643 - in pve-manager/pve2: bin lib/PVE lib/PVE/API2 www/manager

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Mar 3 14:36:36 CET 2011


Author: dietmar
Date: 2011-03-03 14:36:35 +0100 (Thu, 03 Mar 2011)
New Revision: 5643

Modified:
   pve-manager/pve2/bin/pvestatd
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/lib/PVE/REST.pm
   pve-manager/pve2/www/manager/NodeConfig.js
Log:
add test code to view RRD graph


Modified: pve-manager/pve2/bin/pvestatd
===================================================================
--- pve-manager/pve2/bin/pvestatd	2011-03-03 08:48:13 UTC (rev 5642)
+++ pve-manager/pve2/bin/pvestatd	2011-03-03 13:36:35 UTC (rev 5643)
@@ -147,9 +147,9 @@
     RRDs::create ($filename, 
 		  "-b" => $start,
 		  "--step" => 60,
-		  "DS:loadagv:GAUGE:300:0:U",
-		  "DS:cpu:GAUGE:300:0:U",
-		  "DS:iowait:GAUGE:300:0:U",
+		  "DS:loadavg:GAUGE:300:0:U",
+		  "DS:cpu:GAUGE:300:0:1",
+		  "DS:iowait:GAUGE:300:0:1",
 		  "DS:memtotal:GAUGE:300:0:U",
 		  "DS:memused:GAUGE:300:0:U",
 		  "DS:swaptotal:GAUGE:300:0:U",

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-03 08:48:13 UTC (rev 5642)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-03 13:36:35 UTC (rev 5643)
@@ -20,6 +20,7 @@
 use PVE::API2::Storage::Status;
 use PVE::API2::Qemu;
 use JSON;
+use RRDs;
 
 use base qw(PVE::RESTHandler);
 
@@ -69,6 +70,7 @@
 	my $result = [
 	    { name => 'syslog' },
 	    { name => 'status' },
+	    { name => 'rrd' },
 	    { name => 'vncshell' },
 	    { name => 'time' },
 	    { name => 'dns' },
@@ -157,6 +159,63 @@
     }});
 
 __PACKAGE__->register_method({
+    name => 'rrd', 
+    path => 'rrd', 
+    method => 'GET',
+    permissions => {
+	path => '/nodes/{node}',
+	privs => [ 'Sys.Audit' ],
+    },
+    description => "Read node RRD statistics",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	},
+    },
+    returns => {
+	type => "object",
+	properties => {
+	    filename => { type => 'string' },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+# this is just some test code. Using RRD graph is clumsy - maybe it
+# is better to simply fetch the data, and do all display
+# related things with javascript (new extjs html5 graph library).	
+	
+	my $filename = "/tmp/test.png";
+
+	my $rrddir = "/var/lib/rrdcached/db";
+
+	my $rrd = "$rrddir/pve-nodes/$param->{node}";
+
+	# fixme: use cache daemon ?
+
+	RRDs::graph(
+	    $filename,
+	    "--imgformat" => "PNG",
+	    "--border" => 0,
+	    "--height" => 200,
+	    "--width" => 800,
+	    "--vertical-label" => "CPU usage %", 
+	    "--start" => - 60*60,
+	    "--end" => 'now' ,
+	    "DEF:cpu=$rrd:cpu:AVERAGE",
+	    "CDEF:cpuper=cpu,100,*",
+	    "DEF:iowait=$rrd:iowait:AVERAGE",
+	    "CDEF:iowaitper=iowait,100,*",
+	    "LINE2:cpuper#00ddff:cpu usage",
+	    "LINE2:iowaitper#ff0000:io delay",
+	    );
+
+	return { filename => $filename };
+    }});
+
+__PACKAGE__->register_method({
     name => 'syslog', 
     path => 'syslog', 
     method => 'GET',

Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2011-03-03 08:48:13 UTC (rev 5642)
+++ pve-manager/pve2/lib/PVE/REST.pm	2011-03-03 13:36:35 UTC (rev 5643)
@@ -96,6 +96,20 @@
 	}
 	$raw .= "</body></html>";
 
+    } elsif ($format eq 'png') {
+	$ct = 'image/png';
+
+	# fixme: better to revove that whole png thing ?
+
+	my $filename;
+	$raw = '';
+
+	if ($data && ref($data) && ref($data->{data}) && 
+	    $data->{data}->{filename}) {
+	    $filename = $data->{data}->{filename};
+	    $raw = PVE::Tools::file_get_contents($filename);
+	}
+	    
     } elsif ($format eq 'extjs') {
 	$ct = 'application/json';
 	$raw = to_json($data, {utf8 => 1, allow_nonref => 1});
@@ -395,7 +409,7 @@
 sub split_abs_uri {
     my ($abs_uri) = @_;
 
-    my ($format, $rel_uri) = $abs_uri =~ m/^\Q$baseuri\E\/+(html|json|extjs|htmljs)(\/.*)?$/;
+    my ($format, $rel_uri) = $abs_uri =~ m/^\Q$baseuri\E\/+(html|json|extjs|png|htmljs)(\/.*)?$/;
     $rel_uri = '/' if !$rel_uri;
  
     return wantarray ? ($rel_uri, $format) : $rel_uri;

Modified: pve-manager/pve2/www/manager/NodeConfig.js
===================================================================
--- pve-manager/pve2/www/manager/NodeConfig.js	2011-03-03 08:48:13 UTC (rev 5642)
+++ pve-manager/pve2/www/manager/NodeConfig.js	2011-03-03 13:36:35 UTC (rev 5643)
@@ -933,6 +933,18 @@
 
 PVE.NodeStatusView = Ext.extend(PVE.grid.ObjectView, {
 
+    startUpdate: function(delay) {
+	var self = this;
+	if (self.load_task)
+	    self.load_task.delay(delay);
+    },
+
+    stopUpdate: function() {
+	var self = this;
+	if (self.load_task) 
+	    self.load_task.cancel();
+    },
+
     initComponent : function() {
 	var self = this;
 
@@ -988,9 +1000,9 @@
 	    store.load();
 	};
 
-	var load_task = new Ext.util.DelayedTask(function(delay) {
+	self.load_task = new Ext.util.DelayedTask(function(delay) {
 	    update_store();
-	    load_task.delay(delay === undefined ? 1000 : delay);
+	    self.load_task.delay(delay === undefined ? 1000 : delay);
 	});
 
 	Ext.apply(self, {
@@ -998,14 +1010,8 @@
 	    layout: 'fit',
 	    cwidth1: 150,
 	    listeners: {
-		show: function() {
-		    load_task.delay(10);
-		},
-		hide: function() {
-		    load_task.cancel();
-		},
 		destroy: function() {
-		    load_task.cancel();
+		    self.load_task.cancel();
 		}
 	    }
 	});
@@ -1015,6 +1021,60 @@
 });
 Ext.reg('pveNodeStatusView', PVE.NodeStatusView);
 
+PVE.NodeSummaryView = Ext.extend(Ext.Panel, {
+
+    initComponent : function() {
+	var self = this;
+	
+	var nodename = self.nodename;
+
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var statusview = new PVE.NodeStatusView({
+	    width: 802,
+	    height: 350,
+	    nodename: nodename,
+	    title: "Status"
+	});
+
+	Ext.apply(self, {
+	    layout: 'table',
+	    autoScroll: true,
+	    bodyStyle: 'padding:10px',
+	    layoutConfig: {
+		columns: 1
+	    },
+	    defaults: {
+		style: 'padding-top:10px'
+	    },		
+	    items: [
+		statusview,
+		{
+		    title: "CPU usage",
+		    html: {
+			tag: 'img',
+			width: 800,
+			height: 200,
+			src:  "/api2/png/nodes/" + nodename + "/rrd"
+		    }
+		}
+	    ],
+	    listeners: {
+		show: function() {
+		    statusview.startUpdate(10);
+		},
+		hide: function() {
+		    statusview.stopUpdate();
+		}
+	    }
+	});
+
+	PVE.NodeSummaryView.superclass.initComponent.call(self);
+    }
+});
+Ext.reg('pveNodeSummaryView', PVE.NodeSummaryView);
+
 PVE.NodeConfig = Ext.extend(PVE.ConfigPanel, {
 
     initComponent : function() {
@@ -1043,7 +1103,8 @@
 			    }
 			}
 		    ],
-		    xtype: 'pveNodeStatusView',
+		    //xtype: 'pveNodeStatusView',
+		    xtype: 'pveNodeSummaryView',
 		    nodename: nodename
 		},
 		{



More information about the pve-devel mailing list