From: Ian Jackson Date: Sun, 27 Jun 2010 18:36:29 +0000 (+0100) Subject: shows the news graphs X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=3c8f7fb9f89b5eb82c0cf88f15da317f8b427b16;p=rrd-graphs.git shows the news graphs --- diff --git a/cgi b/cgi index 996a5c9..aed4059 100755 --- a/cgi +++ b/cgi @@ -17,19 +17,30 @@ our $SELF= '/home/ijackson/things/rrd-graphs'; my $self= url(-relative=>1); -our (@sections, %sections, %graphs); +our (@sections, %section_groups, %group_elems, %graphs); our @timeranges= (3600, map { $_*86400 } qw(1 7 28), 13*7+1); -sub graph ($$$$) { - my ($section, $gname, $basis, $args) = @_; +sub graph_of_group ($$$$$) { + my ($section, $group, $elem, $basis, $args) = @_; $basis->{Args}= $args; $basis->{Slower}= 0 unless exists $basis->{Slower}; - $graphs{$section,$gname}= $basis; - if (!exists $sections{$section}) { - push @sections, $section; + + $graphs{$section,$group,$elem}= $basis; + if (!exists $group_elems{$section,$group}) { + # new group then + if (!exists $section_groups{$section}) { + # new section even + push @sections, $section; + } + push @{ $section_groups{$section} }, $group; } - push @{ $sections{$section} }, $gname; + push @{ $group_elems{$section,$group} }, $elem; +} + +sub graph ($$$$) { + my ($section, $gname, $basis, $args) = @_; + graph_of_group($section, $gname,'', $basis, $args); } graph('General', 'Load', { }, @@ -137,9 +148,8 @@ foreach my $src (<$SELF/news-stats/*.rrd>) { $site =~ s,_(in|out)$,,; my $inout= $1; $site =~ s/^([-.0-9a-z]+)_//; - my $us= $1; - graph('News', - $inout eq 'out' ? "$us -> $site" : "$site -> $us", + my $us= $1; # all very well but we ignore it + graph_of_group("News", $site, $inout, { Slower => 1, }, $inout eq 'out' ? @@ -196,8 +206,6 @@ navsetting({ }); -my $gname= param('graph'); - sub num_param ($$$$) { my ($param,$def,$min,$max) = @_; my $v= param($param); @@ -208,8 +216,11 @@ sub num_param ($$$$) { return $v + 0; } -if ($gname) { - my $g= $graphs{$section,$gname}; +my $group= param('graph'); + +my $elem= param('elem'); +if (defined $elem) { + my $g= $graphs{$section,$group,$elem}; die unless $g; my @args= @{ $g->{Args} }; @@ -217,17 +228,21 @@ if ($gname) { my $width= num_param('w',370,100,1600); my $height= num_param('h',200,100,1600); - my $end= param('end'); - if (defined $end) { - $end =~ m/^(\d+)$/ or die; - unshift @args, qw(--end now --start), "end-${end}s"; - } + my $sloth= param('sloth'); + die unless defined $sloth; + $sloth =~ m/^(\d+)$/ or die; + my $end= $timeranges[$sloth]; + die unless defined $end; + unshift @args, qw(--end now --start), "end-${end}s"; + if (param('debug')) { print((join "\n",@args),"\n"); exit 0; } print "Content-Type: image/png\n\n"; - my $title= $gname; + my $title= $group; + if (length $elem) { $title.= " $elem"; } + $title .= " $g->{Units}" if $g->{Units}; unshift @args, '-t', $title; @@ -274,12 +289,18 @@ sub start_page ($) { my $detail= param('detail'); if ($detail) { - my $g= $graphs{$section,$detail}; - die unless $g; + my $elems= $group_elems{$section,$detail}; + die unless $elems; start_page("$detail graphs"); - foreach my $end (@timeranges[$g->{Slower}..$g->{Slower}+3]) { - my $imgurl= "$self?graph=$detail§ion=$section&end=$end"; - print "\n"; + foreach my $elem (@$elems) { + my $g= $graphs{$section,$detail,$elem}; + die unless $g; + foreach my $tsloth ($g->{Slower}..$g->{Slower}+3) { + my $imgurl= "$self?graph=$detail§ion=$section". + "&sloth=$tsloth&elem=$elem"; + print ""; + print "\n"; + } } print end_html(); exit 0; @@ -307,11 +328,17 @@ if (param('debug')) { start_page("$section graphs"); -foreach my $gname (@{ $sections{$section} }) { - my $g= $graphs{$section,$gname}; - print ""; - my $end= $timeranges[$g->{Slower}+$sloth]; - my $imgurl= "$self?graph=$gname§ion=$section&end=$end"; - print "\n"; +foreach my $group (@{ $section_groups{$section} }) { + print ""; + my $imgurl= "$self?graph=$group§ion=$section"; + my $elems= $group_elems{$section,$group}; + if (@$elems > 1) { print "
"; } + foreach my $elem (@$elems) { + my $g= $graphs{$section,$group,$elem}; + print "{Slower})."\">"; + } + if (@$elems > 1) { print "
"; } + print "
\n"; }