On Tue, Dec 11, 2001 at 11:21:07PM -0600, Brian wrote:
> On Wed, 12 Dec 2001, Thomas Eibner wrote:
> 
> > Did you get it yet or do people want me to post it here?
> 
> I think people want it posted (I do at least).  That script kicks serious
> ass.

#!/usr/bin/perl -w

use strict;
use GD::Graph::lines;
use POSIX qw(strftime);

my $data_file = 'plot-data';
my $output_file = '/tmp/hest.png';

# end of configurable part

my %messages = ();

open(FH, "$data_file") or die $!;
while (<FH>) {
    chomp;
    my ($time, $count) = split /:\s+/;
    $messages{$time} = $count;
}
close(FH);

my @keys = sort keys %messages;
my @values = ();

foreach my $key (@keys) {
    push @values, $messages{$key};
}

@keys = map { strftime("%d %b", localtime($_)) } @keys;

my $graph = new GD::Graph::lines(400,300);

$graph->set(
	    x_label => 'Time',
	    y_label => 'Count',
	    title => "Number of lkl-messages that need to be injected. Generated: " . scalar localtime(),
	    box_axis => 0,
	    line_width => 2,
	    x_label_position => 1,
	    y_label_position => 1,
	    x_label_skip => 24,
	    transparent => 0
	    );

$graph->set_legend("Messages waiting to be injected");
$graph->plot([\@keys, \@values]);

save_chart($graph);

sub save_chart {
    my $chart = shift or die "Need a chart!";
    open(FH, ">$output_file") or die $!;
    binmode FH;
    print FH $chart->gd->png();
    close(FH);

# Uncomment this to make it into a CGI script:
#
#    my $ext = $chart->export_format;
#    print qq{Content-Type: image/$ext\r\n\r\n};
#    binmode STDOUT;
#    print STDOUT $chart->gd->$ext();
}

__END__

Script just reads in the file Bob exports from mailman with
timestamp: messages
timestamp: messages

-- 
  Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
  mod_pointer <http://stderr.net/mod_pointer>