chiark / gitweb /
disk space
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Jun 2010 18:53:59 +0000 (19:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 25 Jun 2010 18:53:59 +0000 (19:53 +0100)
cgi

diff --git a/cgi b/cgi
index e2860697adfc4b2e65d8f14eee2a9a4d062df8e0..998041a0d6aaf192b24a494f0bac4f9b222cbf49 100755 (executable)
--- a/cgi
+++ b/cgi
@@ -16,16 +16,19 @@ our $R= '/var/lib/collectd/rrd/chiark.greenend.org.uk';
 
 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" }
@@ -36,7 +39,7 @@ graph('Load', { },
        "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)),
@@ -47,7 +50,7 @@ graph('Processes', { },
        "AREA:busy#f00:busy:STACK",
        ]);
 
-graph('CPU', { Units => '[%]' },
+graph('General', 'CPU', { Units => '[%]' },
       [
        (map {
           my $thing= $_;
@@ -64,14 +67,31 @@ graph('CPU', { Units => '[%]' },
        "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} };
@@ -90,16 +110,34 @@ if ($gname) {
     $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&section=$section&end=$end\">\n";
     }
     print end_html();
     exit 0;
@@ -111,11 +149,10 @@ if (param('debug')) {
     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&section=$section\">"; #,h2($gname),"</a>";
+    print "<img src=\"$self?graph=$gname&section=$section\"></a>\n";
 }