[pve-devel] r5980 - in pve-cluster/trunk: data/perl debian

svn-commits at proxmox.com svn-commits at proxmox.com
Mon May 16 10:28:21 CEST 2011


Author: dietmar
Date: 2011-05-16 10:28:21 +0200 (Mon, 16 May 2011)
New Revision: 5980

Modified:
   pve-cluster/trunk/data/perl/Cluster.pm
   pve-cluster/trunk/debian/control
Log:
move RRD code to thzis library


Modified: pve-cluster/trunk/data/perl/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/perl/Cluster.pm	2011-05-13 12:05:43 UTC (rev 5979)
+++ pve-cluster/trunk/data/perl/Cluster.pm	2011-05-16 08:28:21 UTC (rev 5980)
@@ -10,6 +10,7 @@
 use PVE::IPCC;
 use PVE::SafeSyslog;
 use JSON;
+use RRDs;
 use Encode;
 use base 'Exporter';
 
@@ -482,6 +483,121 @@
     return $res;
 }
 
+sub create_rrd_data {
+    my ($rrdname, $timeframe, $cf) = @_;
+
+    my $rrddir = "/var/lib/rrdcached/db";
+
+    my $rrd = "$rrddir/$rrdname";
+
+    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->{$timeframe}};
+    my $ctime  = $reso*int(time()/$reso);
+    my $req_start = $ctime - $reso*$count;
+
+    $cf = "AVERAGE" if !$cf;
+
+    my ($start, $step, $names, $data) = 
+	RRDs::fetch($rrd, $cf,
+		    "-s" => $req_start,
+		    "-e" => $ctime - 1,
+		    "-r" => $reso,
+		    "--daemon" => "unix:/var/run/rrdcached.sock");
+
+    my $err = RRDs::error;
+    die "RRD error: $err\n" if $err;
+    
+    die "got wrong time resolution ($step != $reso)\n" 
+	if $step != $reso;
+
+    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;
+}
+
+sub create_rrd_graph {
+    my ($rrdname, $timeframe, $ds, $cf) = @_;
+
+    # 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 $rrddir = "/var/lib/rrdcached/db";
+
+    my $rrd = "$rrddir/$rrdname";
+
+    my $filename = "$rrd.png";
+
+    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->{$timeframe}};
+
+    my @args = (
+	"--daemon" => "unix:/var/run/rrdcached.sock",	    
+	"--imgformat" => "PNG",
+	"--border" => 0,
+	"--height" => 200,
+	"--width" => 800,
+	"--start" => - $reso*$count,
+	"--end" => 'now' ,
+	);
+
+    my @ids = PVE::Tools::split_list($ds);
+
+    my @coldef = ('#00ddff', '#ff0000');
+
+    $cf = "AVERAGE" if !$cf;
+
+    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;
+
+    return { filename => $filename };
+}
+
 # a fast way to read files (avoid fuse overhead)
 sub get_config {
     my ($path) = @_;

Modified: pve-cluster/trunk/debian/control
===================================================================
--- pve-cluster/trunk/debian/control	2011-05-13 12:05:43 UTC (rev 5979)
+++ pve-cluster/trunk/debian/control	2011-05-16 08:28:21 UTC (rev 5980)
@@ -2,7 +2,7 @@
 Section: unknown
 Priority: extra
 Maintainer: Proxmox Support Team <support at proxmox.com>
-Build-Depends: debhelper (>= 7), autotools-dev, libsqlite3-dev, sqlite3, libfuse-dev, libcorosync-pve-dev, libqb-dev, libpve-common-perl, libglib2.0-dev, librrd-dev, check 
+Build-Depends: debhelper (>= 7), autotools-dev, libsqlite3-dev, sqlite3, libfuse-dev, libcorosync-pve-dev, libqb-dev, libpve-common-perl, libglib2.0-dev, librrd-dev, librrds-perl, rrdcached, check 
 Standards-Version: 3.7.3
 
 Package: pve-cluster




More information about the pve-devel mailing list