From d3c6ef54475f6549e0cbd857d8d8d27f2dcd0836 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 25 Jun 2010 19:53:59 +0100 Subject: [PATCH] disk space --- cgi | 73 ++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/cgi b/cgi index e286069..998041a 100755 --- 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 "$section"; + } else { + print "$s2"; + } + $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 "\n"; + print "\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 ""; #,h2($gname),""; - print "\n"; +foreach my $gname (@{ $sections{$section} }) { + print ""; #,h2($gname),""; + print "\n"; } -- 2.30.2