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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Mar 4 14:08:24 CET 2011


Author: dietmar
Date: 2011-03-04 14:08:24 +0100 (Fri, 04 Mar 2011)
New Revision: 5646

Modified:
   pve-manager/pve2/bin/pvestatd
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/www/manager/NodeConfig.js
Log:
try to use extjs charts to display RRD data


Modified: pve-manager/pve2/bin/pvestatd
===================================================================
--- pve-manager/pve2/bin/pvestatd	2011-03-04 07:19:15 UTC (rev 5645)
+++ pve-manager/pve2/bin/pvestatd	2011-03-04 13:08:24 UTC (rev 5646)
@@ -10,6 +10,7 @@
 use PVE::ProcFSTools;
 use Filesys::Df;
 use PVE::INotify;
+use Time::Local;
 
 initlog('pvestatd');
 
@@ -142,8 +143,11 @@
     return if -f $filename;
 
     my $ctime  = 60*int(time/60);
-    my $start = $ctime - 60*10;
 
+    my (undef, undef, undef, $mday, $mon, $year) = localtime(time);
+    # start at day boundary
+    my $start = timelocal(0,0,0,$mday,$mon,$year);
+
     RRDs::create ($filename, 
 		  "-b" => $start,
 		  "--step" => 60,
@@ -156,11 +160,18 @@
 		  "DS:swapused:GAUGE:300:0:U",
 		  "DS:roottotal:GAUGE:300:0:U",
 		  "DS:rootused:GAUGE:300:0:U",
-		  "RRA:AVERAGE:0.5:1:60", # hourly - 1 min avg
-		  "RRA:AVERAGE:0.5:5:288", # daily - 5 min avg
-		  "RRA:AVERAGE:0.5:30:336", # 7 days - 30 min avg
-		  "RRA:AVERAGE:0.5:120:420", # 5 weeks - 2 hour avg
-		  "RRA:AVERAGE:0.5:1440:366", # yearly - 1 day avg
+		  "RRA:AVERAGE:0.5:1:70", # 1 min avg - one hour
+		  "RRA:AVERAGE:0.5:30:70", # 30 min avg - one day
+		  "RRA:AVERAGE:0.5:180:70", # 3 hour avg - one week
+		  "RRA:AVERAGE:0.5:720:70", # 12 hour avg - one month
+		  "RRA:AVERAGE:0.5:10080:70", # 7 day avg - ony year
+
+# old settings
+#		  "RRA:AVERAGE:0.5:1:60", # hourly - 1 min avg
+#		  "RRA:AVERAGE:0.5:5:288", # daily - 5 min avg
+#		  "RRA:AVERAGE:0.5:30:336", # 7 days - 30 min avg
+#		  "RRA:AVERAGE:0.5:120:420", # 5 weeks - 2 hour avg
+#		  "RRA:AVERAGE:0.5:1440:366", # yearly - 1 day avg
 	);
     check_err();
 

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-04 07:19:15 UTC (rev 5645)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-04 13:08:24 UTC (rev 5646)
@@ -70,7 +70,8 @@
 	my $result = [
 	    { name => 'syslog' },
 	    { name => 'status' },
-	    { name => 'rrd' },
+	    { name => 'rrd' }, # fixme: remove?
+	    { name => 'rrddata' },# fixme: remove?
 	    { name => 'vncshell' },
 	    { name => 'time' },
 	    { name => 'dns' },
@@ -167,7 +168,7 @@
 	privs => [ 'Sys.Audit' ],
     },
     description => "Read node RRD statistics",
-    proxyto => 'node',
+#    proxyto => 'node',
     parameters => {
     	additionalProperties => 0,
 	properties => {
@@ -216,6 +217,88 @@
     }});
 
 __PACKAGE__->register_method({
+    name => 'rrddata', 
+    path => 'rrddata', 
+    method => 'GET',
+    protected => 1, # fixme: can we avoid that?
+    permissions => {
+	path => '/nodes/{node}',
+	privs => [ 'Sys.Audit' ],
+    },
+    description => "Read node RRD statistics",
+#    proxyto => 'node',
+    parameters => {
+    	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' ],
+	    }
+	},
+    },
+    returns => {
+	type => "array",
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $rrddir = "/var/lib/rrdcached/db";
+	my $filename = "$rrddir/pve-nodes/$param->{node}";
+
+	my $setup = {
+	    hour =>  [ 60, 70 ],
+	    day  =>  [ 60*30, 70 ],
+	    week =>  [ 60*180, 70 ],
+	    month => [ 60*720, 70 ],
+	    year =>  [ 60*10080, 70 ],
+	};
+
+	my ($reso, $count) = @{$setup->{$param->{timeframe}}};
+	my $ctime  = $reso*int(time()/$reso);
+	my $req_start = $ctime - $reso*$count;
+
+	my ($start, $step, $names, $data) = 
+	    RRDs::fetch($filename, 'AVERAGE',
+			"-s" => $req_start,
+			"-e" => $ctime - 1,
+			"-r" => $reso,
+			"--daemon" => "unix:/var/run/rrdcached.sock");
+
+	die "got wrong time resolution ($step != $reso)\n" 
+	    if $step != $reso;
+
+	my $err = RRDs::error;
+	die "RRD error: $err\n" if $err;
+
+	my $res = [];
+	my $fields = scalar(@$names);
+	for my $line (@$data) {
+	    my $entry = { 'time' => $start };
+	    $start += $step;
+	    my $found_undefs;
+	    for (my $i = 0; $i < $fields; $i++) {
+		my $name = $names->[$i];
+		if (defined(my $val = $line->[$i])) {
+		    $entry->{$name} = $val;
+		} else {
+		    # we only add entryies with all data defined
+		    # extjs chart has problems with undefined values
+		    $found_undefs = 1;
+		}
+	    }
+	    push @$res, $entry if !$found_undefs;
+	}
+
+	return $res;
+    }});
+
+__PACKAGE__->register_method({
     name => 'syslog', 
     path => 'syslog', 
     method => 'GET',

Modified: pve-manager/pve2/www/manager/NodeConfig.js
===================================================================
--- pve-manager/pve2/www/manager/NodeConfig.js	2011-03-04 07:19:15 UTC (rev 5645)
+++ pve-manager/pve2/www/manager/NodeConfig.js	2011-03-04 13:08:24 UTC (rev 5646)
@@ -1021,6 +1021,90 @@
 });
 Ext.reg('pveNodeStatusView', PVE.NodeStatusView);
 
+// fixme: create generic class
+PVE.RRDView = Ext.extend(Ext.Panel, {
+
+    initComponent : function() {
+	var self = this;
+
+	var timeframe = 'hour';
+
+	var majorunit;
+
+	var timefmt;
+	if (timeframe == 'hour') {
+	    timefmt = "H:i";
+	} else if (timeframe == 'day') {
+	    timefmt = "D H:i";
+	} else if (timeframe == 'week') {
+	    timefmt = "D H:i";
+	} else {
+	    timefmt = "D j H:i";
+	}
+
+	var store = new PVE.data.UpdateStore({
+	    interval: 3000,
+	    itype: 'rrd',
+	    idProperty: 'time',
+	    autoDestroy: true,
+	    url: '/api2/json/nodes/maui/rrddata?timeframe=' + timeframe,
+	    fields: [ 
+		{ name: 'time', type : 'date', dateFormat: 'timestamp' }, 
+		'cpu', 'iowait']
+	});
+
+	self.store = store;
+
+	//store.startUpdate();
+
+	Ext.apply(self, {
+	    layout: 'fit',
+            items: {
+		xtype: 'linechart',
+		store: store,
+		xField: 'time',
+		yAxis: new Ext.chart.NumericAxis({
+		    labelRenderer: function(val) { 
+			return (val*100).toFixed(2) + "%";
+		    }
+		}),
+		xAxis: new Ext.chart.TimeAxis({
+		    labelRenderer: function(val) { 
+			return Ext.util.Format.date(val, timefmt); 
+		    }
+		}),
+		chartStyle: {
+		    xAxis: {
+			majorGridLines: {size: 1, color: 0xeeeeee}
+		    },
+                    yAxis: {
+			majorGridLines: {size: 1, color: 0xdfe8f6}
+                    }
+		},
+		series: [
+		    {
+			type: 'line',
+			displayName: 'CPU',
+			yField: 'cpu',
+		    },
+		    {
+			type: 'line',
+			displayName: 'IO delay',
+			yField: 'iowait',
+			style: {
+			    color:0xff0000
+			}
+		    }
+		]
+	    }
+	});
+
+	PVE.NodeSummaryView.superclass.initComponent.call(self);
+    }
+});
+Ext.reg('pveRRDView', PVE.RRDView);
+	
+
 PVE.NodeSummaryView = Ext.extend(Ext.Panel, {
 
     initComponent : function() {
@@ -1038,6 +1122,12 @@
 	    title: "Status"
 	});
 
+	var cpustat = new PVE.RRDView({
+	    width: 800,
+	    height: 200,
+	    title: "CPU usage"
+	});
+
 	Ext.apply(self, {
 	    layout: 'table',
 	    autoScroll: true,
@@ -1050,6 +1140,7 @@
 	    },		
 	    items: [
 		statusview,
+		cpustat,
 		{
 		    title: "CPU usage",
 		    html: {
@@ -1063,9 +1154,11 @@
 	    listeners: {
 		show: function() {
 		    statusview.startUpdate(10);
+		    cpustat.store.startUpdate();
 		},
 		hide: function() {
 		    statusview.stopUpdate();
+		    cpustat.store.stopUpdate();
 		}
 	    }
 	});




More information about the pve-devel mailing list