my $self= url(-relative=>1);
-our (@graphs, %graphs);
+our (@sections, %sections, %graphs);
-sub graph ($$$) {
- my ($gname, $basis, $args) = @_;
+sub graph ($$$$) {
+ my ($section, $gname, $basis, $args) = @_;
$basis->{Args}= $args;
- $graphs{$gname}= $basis;
- push @graphs, $gname;
+ $graphs{$section,$gname}= $basis;
+ if (!exists $sections{$section}) {
+ push @sections, $section;
+ }
+ push @{ $sections{$section} }, $gname;
}
-graph('Load', { },
+graph('General', 'Load', { },
[
"DEF:load=$R/load/load.rrd:shortterm:AVERAGE",
(map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
"LINE:load#000:load",
]);
-graph('Processes', { },
+graph('General', 'Processes', { },
[
(map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
qw(blocked running stopped paging sleeping zombies)),
"AREA:busy#f00:busy:STACK",
]);
-graph('CPU', { Units => '[%]' },
+graph('General', 'CPU', { Units => '[%]' },
[
(map {
my $thing= $_;
"AREA:steal#0ff:steal:STACK",
]);
+foreach my $src (<$R/df/df-*.rrd>) {
+ my $vol= $src;
+ $vol =~ s,.*/,,;
+ $vol =~ s,^df-,,;
+ $vol =~ s,\.rrd$,,;
+ graph('Disk space', $vol, { },
+ [
+ qw(-b 1024 -l 0),
+ (map { "DEF:$_=$src:$_:AVERAGE" } qw(free used)),
+ "AREA:used#000:used:STACK",
+ "AREA:free#88f:free:STACK",
+ ]);
+}
+
if (param('debug')) {
print "Content-Type: text/plain\n\n";
}
my $gname= param('graph');
+my $section= param('section');
+$section ||= $sections[0];
+die unless $sections{$section};
if ($gname) {
- my $g= $graphs{$gname};
+ my $g= $graphs{$section,$gname};
die unless $g;
my @args= @{ $g->{Args} };
$title .= " $g->{Units}" if $g->{Units};
unshift @args, '-t', $title;
- exec qw(rrdtool graph - -a PNG --full-size-mode -w 380 -h 200), @args;
+ exec qw(rrdtool graph - -a PNG --full-size-mode -w 370 -h 200), @args;
die $!;
}
+sub start_page ($) {
+ my ($title) = @_;
+ print header(), start_html($title);
+ my $delim= '';
+ foreach my $s2 (@sections) {
+ print $delim;
+ if ($s2 eq $section) {
+ print "<b>$section</b>";
+ } else {
+ print "<a href=\"$self";
+ if ($s2 ne $sections[0]) { print "?section=$s2"; }
+ print "\">$s2</a>";
+ }
+ $delim= ' | ';
+ }
+ print h1("$title");
+}
+
my $detail= param('detail');
if ($detail) {
- die unless $graphs{$detail};
- print header(), start_html(), h1("$detail graphs");
+ die unless $graphs{$section,$detail};
+ start_page("$detail graphs");
foreach my $end (qw(3600 86400 604800 2419200)) {
- print "<img src=\"$self?graph=$detail&end=$end\">\n";
+ print "<img src=\"$self?graph=$detail§ion=$section&end=$end\">\n";
}
print end_html();
exit 0;
exit 0;
}
-print header(), start_html();
-print h1('Graphs');
+start_page("$section graphs");
-foreach my $gname (@graphs) {
- print "<a href=\"$self?detail=$gname\">"; #,h2($gname),"</a>";
- print "<img src=\"$self?graph=$gname\"></a>\n";
+foreach my $gname (@{ $sections{$section} }) {
+ print "<a href=\"$self?detail=$gname§ion=$section\">"; #,h2($gname),"</a>";
+ print "<img src=\"$self?graph=$gname§ion=$section\"></a>\n";
}