#!/usr/bin/perl -w use strict qw(vars); use CGI qw/:standard/; sub fail ($) { print(header(-status=>500), start_html('Error'), h1('Error'), escapeHTML($_[0]), end_html()); exit 0; } our $R= '/var/lib/collectd/rrd/chiark.greenend.org.uk'; my $self= url(-relative=>1); our (@graphs, %graphs); sub graph ($$$) { my ($gname, $basis, $args) = @_; $basis->{Args}= $args; $graphs{$gname}= $basis; push @graphs, $gname; } graph('Load', { }, [ "DEF:load=$R/load/load.rrd:shortterm:AVERAGE", (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" } qw(blocked running stopped paging sleeping zombies)), "AREA:running#88f:running processes:STACK", "AREA:blocked#8f8:blocked processes:STACK", "AREA:paging#f88:paging processes:STACK", "LINE:load#000:load", ]); graph('Processes', { }, [ (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" } qw(blocked running stopped paging sleeping zombies)), "CDEF:busy=0".(join '', map { ",$_,+" } qw(running blocked paging)), "AREA:sleeping#ccc:sleeping:STACK", "AREA:stopped#f00:stopped:STACK", "AREA:zombies#0f0:zombie:STACK", "AREA:busy#f00:busy:STACK", ]); graph('CPU', { Units => '[%]' }, [ (map { my $thing= $_; (map { "DEF:$thing$_=$R/cpu-$_/cpu-$thing.rrd:value:AVERAGE" } (0..7)), "CDEF:$thing=0".join('', map { ",$thing$_,+" } (0..7)).",8.0,/"; } qw(idle interrupt nice softirq steal system user wait)), "AREA:system#00f:system:STACK", "AREA:wait#f88:wait:STACK", "AREA:nice#ccc:nice:STACK", "AREA:user#080:user:STACK", "AREA:softirq#f0f:softirq:STACK", "AREA:interrupt#ff0:interrupt:STACK", "AREA:steal#0ff:steal:STACK", ]); if (param('debug')) { print "Content-Type: text/plain\n\n"; } my $gname= param('graph'); if ($gname) { my $g= $graphs{$gname}; die unless $g; my @args= @{ $g->{Args} }; my $end= param('end'); if (defined $end) { $end =~ m/^(\d+)$/ or die; 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; $title .= " $g->{Units}" if $g->{Units}; unshift @args, '-t', $title; exec qw(rrdtool graph - -a PNG --full-size-mode -w 380 -h 200), @args; die $!; } my $detail= param('detail'); if ($detail) { die unless $graphs{$detail}; print header(), start_html(), h1("$detail graphs"); foreach my $end (qw(3600 86400 604800 2419200)) { print "\n"; } print end_html(); exit 0; } if (param('debug')) { use Data::Dumper; print Dumper(\%graphs); exit 0; } print header(), start_html(); print h1('Graphs'); foreach my $gname (@graphs) { print ""; #,h2($gname),""; print "\n"; }