#!/usr/bin/speedy -w -- -t100 -M1
+# -*- perl -*-
+# Main CGI program's logic; must be run inside a lock.
+
+# rrd-graphs/cgi - part of rrd-graphs, a tool for online graphs
+# Copyright 2010, 2012 Ian Jackson
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
use strict qw(vars);
use CGI::SpeedyCGI qw/:standard -no_xhtml/;
our @timeranges= (3600, map { $_*86400 } qw(1 7 28), 13*7+1, 366);
-sub graph_of_group ($$$$$) {
- my ($section, $group, $elem, $basis, $args) = @_;
+sub graph_of_group ($$$$$;$) {
+ my ($section, $group, $elem, $basis, $args, $title) = @_;
$basis->{Args}= $args;
$basis->{Slower}= 0 unless exists $basis->{Slower};
$basis->{TimeRanges} ||= \@timeranges;
+ if (!defined $title) {
+ $title = $group;
+ if (length $elem) { $title.= " $elem"; }
+ }
+ $basis->{Title} = $title;
$graphs{$section,$group,$elem}= $basis;
if (!exists $group_elems{$section,$group}) {
# new group then
foreach my $site (keys %news_sources) {
my $sk= $site;
+ $sk =~ s/^[.0-9]+$/~$&/;
for (;;) {
last unless $sk =~
- s/^[^.]*(?:chiark|greenend|news|nntp|peer|feed|in|out)[^.]*\.//;
+ s/^[^. ]*\b(?:chiark|greenend|news|newsfeed|nntp|peer|feed|in|out)\b[^.]*\.//;
$sk .= " $&";
}
+print STDERR "$site => $sk\n";
foreach my $inout (keys %{ $news_sources{$site} }) {
- push @news_graphs, [ "$sk $inout", $site, $inout ];
+ my $skio = $sk;
+ $skio =~ s/ / [$inout]/;
+ push @news_graphs, [ $skio, $site, $inout ];
}
}
push @defs, "CDEF:kb_$`=$val,1024,/";
}
}
- graph_of_group("News", $site, $inout,
+ my $group = $sortkey;
+ $group =~ s/ .*//;
+ $group = $site unless length $group;
+ graph_of_group("News", $group, "$site $inout",
{
Units => '[art/s]',
TimeRanges => [ map { $_*86400 } qw(1 7 31), 366, 366*3 ]
"CDEF:kb_accepted_smooth=kb_accepted,<interval/60>,TREND",
"LINE:kb_duplicate#ff0:kb dupe",
"LINE:kb_accepted_smooth#008:~kb",
- ]);
+ ],
+ "$site $inout");
}
our %disk_rdev2rrd;
print "Content-Type: text/plain\n\n";
}
+sub source_tarball ($$) {
+ my ($spitoutfn) = @_;
+}
+
+if (path_info() =~ m/\.tar\.gz$/) {
+ print "Content-Type: application/octet-stream\n\n";
+
+ exec '/bin/sh','-c','
+ (
+ git-ls-files -z;
+ git-ls-files -z --others --exclude-from=.gitignore;
+ if test -d .git; then find .git -print0; fi
+ ) | (
+ cpio -Hustar -o --quiet -0 -R 1000:1000 || \
+ cpio -Hustar -o --quiet -0
+ ) | gzip
+ ';
+ die $!;
+}
+
our @navsettings;
@navsettings= ();
our $group= param('graph');
+my $defwidth= 370;
+my $defheight= 200;
+
our $elem= param('elem');
if (defined $elem) {
my $g= $graphs{$section,$group,$elem};
die unless $g;
- my $width= num_param('w',370,100,1600);
- my $height= num_param('h',200,100,1600);
+ my $width= num_param('w',$defwidth,100,1600);
+ my $height= num_param('h',$defheight,100,1600);
my $sloth= param('sloth');
die unless defined $sloth;
s,\<interval/(\d+)\>, $end/$1 ,ge foreach @args;
unshift @args, qw(--end now --start), "end-${end}s";
- my $title= $group;
- if (length $elem) { $title.= " $elem"; }
-
+ my $title = $g->{Title};
$title .= " $g->{Units}" if $g->{Units};
unshift @args, '-t', $title, '-w',$width, '-h',$height;
unshift @args, qw(-a PNG --full-size-mode);
my $imgurl= "$self?graph=$detail§ion=$section".
"&sloth=$tsloth&elem=$elem";
print a({href=>"$imgurl&w=780&h=800"},
- img({src=>$imgurl, alt=>''}));
+ img({src=>$imgurl, alt=>'',
+ width=>$defwidth, height=>$defheight}));
}
}
print end_html();
foreach my $elem (@$elems) {
my $g= $graphs{$ref_section,$ref_group,$elem};
print img({src=>"$imgurl&elem=$elem&sloth=".($sloth + $g->{Slower}),
- alt=>''});
+ alt=>'', width=>$defwidth, height=>$defheight});
}
print "</span>";
print "</a>\n";
}
+my $homeurl =
+ 'http://www.chiark.greenend.org.uk/ucgi/~ijackson/git/rrd-graphs/';
+print <<END
+<hr>Generated by "<a href="$homeurl">rrd-graphs</a>".
+Copyright 2010,2012 Ian Jackson. There is <strong>NO WARRANTY</strong>.
+Available under the Affero Public General Licence, version 3 or any
+later version. You may download the
+<a href="$self/rrd-graphs.tar.gz">source code</a>
+for the version currently running here.
+END