[rrd-developers] Re: PIE CHART ???

Keith Sinclair keith at sinclair.org.au
Thu Jun 6 03:39:49 MEST 2002


Michael,

I have done some graphs with GD::Graph which is pretty nice.  I have also
written some code to dump an RRD to a perl hash (ass. array) so combining
these two bits you could have a Pie Chart pretty quickly.  Code below, needs
tie'ing together but should be enough, would need to massage the data a
little before sticking into a PIE chart, need to do some quick
consolidation/summarisation, I have been meaning to whip something up but
busy with work.

Regards


Keith

# get stats
my ($statval,$head) = &getRRDasHash(rrd => $rrdfile, type => "AVERAGE",
start => $args{start}, end => $args{end});

# walk stats and do something with them (prints out as CSV file)
	print "Content-type: text/plain\n\n";
	foreach my $m (sort keys %{$statval}) {
		if ($f) {
			$f = 0;
			foreach my $h (@$head) {
				push(@line,$h);
				print STDERR "@line\n";
			}
			#print STDERR "@line\n";
			$row = join("\t", at line);
			print "$row\n";
			@line = ();
		}
		$content = 0;
		foreach my $h (@$head) {
			if ( defined $statval->{$m}{$h}) {
				$content = 1;
			}
			push(@line,$statval->{$m}{$h});
		}
		if ( $content ) {
			$row = join("\t", at line);
			print "$row\n";
		}
		@line = ();
	}

# draw a pie chart
use GD::Graph::pie3d;
if ( -r $config{Technology_Table} ) {
	print &elapTime($stime) ." Technology Graph $config{Technology_Table}\n";
	my %tech_list = loadCSV($config{Technology_Table},$config{Technology_Key});
	@data;
	@d1;
	@d2;
	@d3;
	$i = 0;
	$max = 0;
	foreach my $key ( sort (keys %tech_list) ) {
		if  ($tech_list{$key}{type} eq "Technology" ) {
			if ( $max < $tech_list{$key}{count} ) {
				$max = $tech_list{$key}{count};
			}
			$d1[$i] = "$tech_list{$key}{technology}";
			$d2[$i] = $tech_list{$key}{count};
			++$i;
		}
	}
	@data = ( [@d1], [@d2] );

	my $graph = GD::Graph::pie3d->new(640, 480);
	$graph->set(
		x_label           => 'Technology',
		y_label           => 'Node Count',
		#title             => 'Technology Profile',
		x_labels_vertical => 1,
		y_max_value       => $max,
		y_tick_number     => 8,
		y_label_skip      => 2
	);
	my $gd = $graph->plot(\@data);
	open(IMG, ">$config{tech_image}") or die "ERROR with $config{tech_image}.
$!\n";
	binmode IMG;
	print IMG $gd->png;
	close IMG;
}


sub getRRDasHash {
	my %arg = @_;
	my ($begin,$step,$name,$data) =
RRDs::fetch($arg{rrd},$arg{type},"--start",$arg{start},"--end",$arg{end});
	my %s;
	my @h;
	my $f = 1;
	my $date;
	my $d;
	my $time = $begin;
	for(my $a = 0; $a <= $#{$data}; ++$a) {
		$d = 0;
		for(my $b = 0; $b <= $#{$data->[$a]}; ++$b) {
			if ($f) { push(@h,$name->[$b]) }
			$s{$time}{$name->[$b]} = $data->[$a][$b];
			if ( defined $data->[$a][$b] ) { $d = 1; }
		}
		if ($d) {
			$date = returnDateStamp($time);
			$s{$time}{time} = $time;
			$s{$time}{date} = $date;
		}
		if ($f) {
			push(@h,"time");
			push(@h,"date");
		}
		$f = 0;
		$time = $time + $step;
	}
	return (\%s,\@h);
}

> -----Original Message-----
> From: rrd-developers-bounce at list.ee.ethz.ch
> [mailto:rrd-developers-bounce at list.ee.ethz.ch]On Behalf Of Michael T.
> Babcock
> Sent: Wednesday, June 05, 2002 10:09 AM
> To: rrd-developers at list.ee.ethz.ch
> Subject: [rrd-developers] Re: PIE CHART ???
>
>
>
> > Hi, is there a way to graph PIE Charts using RRD ?
>
> It would be nice to have a good graphing tool that used the rrdtool
> libraries as a back-end.  On second thought, however, there are some
> good graphing libraries out there that do a lot more than what rrdtool
> does now.  Instead of reimplementing them, why not pick one and write an
> input module to rrdtool's database format for them, using an
> intermediary file to describe the data wanted (as per my prior
> XML-related message)?
>
> Some quick examples:
> http://www.aditus.nu/jpgraph/
> http://ourworld.compuserve.com/homepages/jsieberer/
> http://www.tulip-software.org/
> http://www.phplot.com/
> --
> Michael T. Babcock
> CTO, FibreSpeed Ltd.
> http://www.fibrespeed.net/~mbabcock/
>
> --
> Unsubscribe
> mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
> Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
> Archive     http://www.ee.ethz.ch/~slist/rrd-developers
> WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi
>

--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list