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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Mar 11 15:20:10 CET 2011


Author: dietmar
Date: 2011-03-11 15:20:10 +0100 (Fri, 11 Mar 2011)
New Revision: 5687

Modified:
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/lib/PVE/REST.pm
   pve-manager/pve2/www/manager/NodeConfig.js
Log:
use rrd graph again 


Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-11 07:59:40 UTC (rev 5686)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-11 14:20:10 UTC (rev 5687)
@@ -174,6 +174,21 @@
     	additionalProperties => 0,
 	properties => {
 	    node => get_standard_option('pve-node'),
+	    timeframe => {
+		description => "Specify the time frame you are interested in.",
+		type => 'string',
+		enum => [ 'hour', 'day', 'week', 'month', 'year' ],
+	    },
+	    ds => {
+		description => "The list of datasources you want to display.",
+ 		type => 'string', format => 'pve-configid-list',
+	    },
+	    cf => {
+		description => "The RRD consolidation function",
+ 		type => 'string',
+		enum => [ 'AVERAGE', 'MAX' ],
+		optional => 1,
+	    },
 	},
     },
     returns => {
@@ -189,32 +204,52 @@
 # 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/pve2-node/$param->{node}";
 
-	# fixme: use cache daemon ?
+	my $filename = "$rrd.png";
 
-	RRDs::graph(
-	    $filename,
+	my $setup = {
+	    hour =>  [ 60, 60 ],
+	    day  =>  [ 60*30, 70 ],
+	    week =>  [ 60*180, 70 ],
+	    month => [ 60*720, 70 ],
+	    year =>  [ 60*10080, 70 ],
+	};
+
+	my ($reso, $count) = @{$setup->{$param->{timeframe}}};
+
+	my @args = (
 	    "--daemon" => "unix:/var/run/rrdcached.sock",	    
 	    "--imgformat" => "PNG",
 	    "--border" => 0,
 	    "--height" => 200,
 	    "--width" => 800,
-	    "--vertical-label" => "CPU usage %", 
-	    "--start" => - 60*60,
+	    "--start" => - $reso*$count,
 	    "--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",
 	    );
 
+	my @ids = PVE::Tools::split_list($param->{ds});
+
+	my @coldef = ('#00ddff', '#ff0000');
+
+	my $cf = $param->{cf} || "AVERAGE";
+
+	my $i = 0;
+	foreach my $id (@ids) {
+	    my $col = $coldef[$i++] || die "fixme: no color definition";
+	    push @args, "DEF:${id}=$rrd:${id}:$cf";
+	    my $dataid = $id;
+	    if ($id eq 'cpu' || $id eq 'iowait') {
+		push @args, "CDEF:${id}_per=${id},100,*";
+		$dataid = "${id}_per";
+	    }
+	    push @args, "LINE2:${dataid}${col}:${id}";
+	}
+
+	RRDs::graph($filename, @args);
+
 	my $err = RRDs::error;
 	die "RRD error: $err\n" if $err;
 

Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2011-03-11 07:59:40 UTC (rev 5686)
+++ pve-manager/pve2/lib/PVE/REST.pm	2011-03-11 14:20:10 UTC (rev 5687)
@@ -323,6 +323,8 @@
 	};
     }
 
+    delete $params->{_dc}; # remove disable cache parameter
+
     foreach my $p (keys %{$params}) {
 	if (defined($uri_param->{$p})) {
 	    return {

Modified: pve-manager/pve2/www/manager/NodeConfig.js
===================================================================
--- pve-manager/pve2/www/manager/NodeConfig.js	2011-03-11 07:59:40 UTC (rev 5686)
+++ pve-manager/pve2/www/manager/NodeConfig.js	2011-03-11 14:20:10 UTC (rev 5687)
@@ -1099,12 +1099,97 @@
 	    }
 	});
 
-	PVE.NodeSummaryView.superclass.initComponent.call(self);
+	PVE.RRDView.superclass.initComponent.call(self);
     }
 });
 Ext.reg('pveRRDView', PVE.RRDView);
+
+PVE.RRDGraph = Ext.extend(Ext.Panel, {
+
+    initComponent : function() {
+	var self = this;
+
+	if (!self.timeframe) 
+	    self.timeframe = 'hour';
+	if (!self.rrdcffn)
+	    self.rrdcffn = 'AVERAGE';
+
+	var datasource = self.datasource;
+
+	var dcindex = 0;
+	var create_url = function() {
+	    var url = self.rrdurl + "?ds=" + datasource + 
+		"&timeframe=" + self.timeframe + "&cf=" + self.rrdcffn +
+		"&_dc=" + dcindex;
+	    dcindex++;
+	    return url;
+	}
+
+	var stateid = 'pverrdtypeselection';
+
+	Ext.apply(self, {
+	    layout: 'fit',
+	    html: {
+		tag: 'img',
+		width: 800,
+		height: 200,
+		src:  create_url()
+	    },
+	    stateful: true,
+	    stateId: stateid,    
+	    applyState : function(state) {
+		if (state && state.id) {
+		    self.timeframe = state.timeframe;
+		    self.rrdcffn = state.cf;
+		    self.reload.defer(10, self);
+		}
+	    }
+
+	});
 	
+	PVE.RRDGraph.superclass.initComponent.call(self);
 
+	self.reload = function() {
+	    //console.log("RELOAD");
+	    if (self.rendered) {
+		try {
+		    var html = {
+			tag: 'img',
+			width: 800,
+			height: 200,
+			src:  create_url()
+		    };
+		    self.update(html);
+		} catch (e) {
+		    // console.log(e);
+		}
+		self.reload.defer(30000, self);
+	    } else {
+		self.reload.defer(1000, self);
+	    }
+	};
+
+	self.reload.defer(30000, self);
+
+	var sp = Ext.state.Manager.getProvider();
+
+	var state_change_fn = function(prov, key, value) {
+	    if (key == stateid) {
+		self.timeframe = value.timeframe;
+		self.rrdcffn = value.cf;
+		self.reload.defer(10, self);
+	    }
+	};
+
+	sp.on('statechange', state_change_fn);
+
+	self.on('destroy', function() {
+	    sp.un('statechange', state_change_fn);
+	});
+     }
+});
+Ext.reg('pveRRDGraph', PVE.RRDGraph);
+
 PVE.NodeSummaryView = Ext.extend(Ext.Panel, {
 
     initComponent : function() {
@@ -1122,12 +1207,54 @@
 	    title: "Status"
 	});
 
-	var cpustat = new PVE.RRDView({
-	    width: 802,
-	    height: 200,
-	    title: "CPU usage"
+	var rrdurl = "/api2/png/nodes/" + nodename + "/rrd";
+
+	var rdtstore = new Ext.data.ArrayStore({
+            fields: [ 'id', 'timeframe', 'cf', 'text' ],
+            data : [
+		[ 'hour', 'hour', 'AVERAGE', "Hour (average)" ],
+		[ 'hourmax', 'hour', 'MAX', "Hour (max)" ],
+		[ 'day', 'day', 'AVERAGE', "Day (average)" ],
+		[ 'daymax', 'day', 'MAX', "Day (max)" ],
+		[ 'week', 'week', 'AVERAGE', "Week (average)" ],
+		[ 'weekmax', 'week', 'MAX', "Week (max)" ],
+		[ 'month', 'month', 'AVERAGE', "Month (average)" ],
+		[ 'monthmax', 'month', 'MAX', "Month (max)" ],
+		[ 'year', 'year', 'AVERAGE', "Year (average)" ],
+		[ 'yearmax', 'year', 'MAX', "Year (max)" ],
+	    ]
 	});
 
+	var rdtcombo = new Ext.form.ComboBox({
+            store: rdtstore,
+            displayField: 'text',
+	    valueField: 'id',
+	    allowBlank: false,
+ 	    editable: false,
+            autoSelect: true,
+            mode: 'local',
+	    value: 'hour',
+            triggerAction: 'all',
+	    getState: function() {
+		var ind = rdtstore.findExact('id', this.getValue());
+		var rec = rdtstore.getAt(ind);
+		if (!rec) return;
+		return { 
+		    id: rec.data.id,
+		    timeframe: rec.data.timeframe,
+		    cf: rec.data.cf
+		};
+	    },
+	    applyState : function(state) {
+		if (state && state.id) {
+		    this.setValue(state.id);
+		}
+	    },
+	    stateEvents: [ 'select' ],
+	    stateful: true,
+	    stateId: 'pverrdtypeselection'        
+	});
+    
 	Ext.apply(self, {
 	    layout: 'table',
 	    autoScroll: true,
@@ -1136,29 +1263,53 @@
 		columns: 1
 	    },
 	    defaults: {
-		style: 'padding-top:10px'
+		style: 'padding-bottom:10px'
 	    },		
+	    tbar: [ 
+		{ text: 'Reboot' }, '-',
+		{ text: 'Shutdown' }, '-',
+		{ 
+		    text: 'Console',
+		    handler: function() { 
+			PVE.newShellWindow(nodename);
+		    }
+		},
+		'->',
+		rdtcombo
+	    ],
 	    items: [
 		statusview,
-		cpustat,
 		{
-		    title: "CPU usage",
-		    html: {
-			tag: 'img',
-			width: 800,
-			height: 200,
-			src:  "/api2/png/nodes/" + nodename + "/rrd"
-		    }
+		    xtype: 'pveRRDGraph',
+		    title: "CPU usage %",
+		    datasource: 'cpu,iowait',
+		    rrdurl: rrdurl
+		},
+		{
+		    xtype: 'pveRRDGraph',
+		    title: "Server load",
+		    datasource: 'loadavg',
+		    rrdurl: rrdurl
+		},
+		{
+		    xtype: 'pveRRDGraph',
+		    title: "Memory usage",
+		    datasource: 'memtotal,memused',
+		    rrdurl: rrdurl
+		},
+		{
+		    xtype: 'pveRRDGraph',
+		    title: "Network traffic",
+		    datasource: 'netin,netout',
+		    rrdurl: rrdurl
 		}
 	    ],
 	    listeners: {
 		show: function() {
 		    statusview.startUpdate(10);
-		    cpustat.store.startUpdate();
 		},
 		hide: function() {
 		    statusview.stopUpdate();
-		    cpustat.store.stopUpdate();
 		}
 	    }
 	});
@@ -1186,16 +1337,6 @@
 		{
 		    title: 'Summary',
 		    id: 'summary',
-		    tbar: [ 
-			{ text: 'Reboot' }, '-',
-			{ text: 'Shutdown' }, '-',
-			{ 
-			    text: 'Console',
-			    handler: function() { 
-				PVE.newShellWindow(nodename);
-			    }
-			}
-		    ],
 		    //xtype: 'pveNodeStatusView',
 		    xtype: 'pveNodeSummaryView',
 		    nodename: nodename



More information about the pve-devel mailing list