7 print(header(-status=>500),
15 our $R= '/var/lib/collectd/rrd/chiark.greenend.org.uk';
17 my $self= url(-relative=>1);
19 our (@graphs, %graphs);
22 my ($gname, $basis, $args) = @_;
23 $basis->{Args}= $args;
24 $graphs{$gname}= $basis;
30 "DEF:load=$R/load/load.rrd:shortterm:AVERAGE",
31 (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
32 qw(blocked running stopped paging sleeping zombies)),
33 "AREA:running#88f:running processes:STACK",
34 "AREA:blocked#8f8:blocked processes:STACK",
35 "AREA:paging#f88:paging processes:STACK",
39 graph('Processes', { },
41 (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
42 qw(blocked running stopped paging sleeping zombies)),
43 "CDEF:busy=0".(join '', map { ",$_,+" } qw(running blocked paging)),
44 "AREA:sleeping#ccc:sleeping:STACK",
45 "AREA:stopped#f00:stopped:STACK",
46 "AREA:zombies#0f0:zombie:STACK",
47 "AREA:busy#f00:busy:STACK",
50 graph('CPU', { Units => '[%]' },
54 (map { "DEF:$thing$_=$R/cpu-$_/cpu-$thing.rrd:value:AVERAGE" }
56 "CDEF:$thing=0".join('', map { ",$thing$_,+" } (0..7)).",8.0,/";
57 } qw(idle interrupt nice softirq steal system user wait)),
58 "AREA:system#00f:system:STACK",
59 "AREA:wait#f88:wait:STACK",
60 "AREA:nice#ccc:nice:STACK",
61 "AREA:user#080:user:STACK",
62 "AREA:softirq#f0f:softirq:STACK",
63 "AREA:interrupt#ff0:interrupt:STACK",
64 "AREA:steal#0ff:steal:STACK",
68 print "Content-Type: text/plain\n\n";
71 my $gname= param('graph');
74 my $g= $graphs{$gname};
77 my @args= @{ $g->{Args} };
79 my $end= param('end');
81 $end =~ m/^(\d+)$/ or die;
82 unshift @args, qw(--end now --start), "end-${end}s";
85 print((join "\n",@args),"\n"); exit 0;
87 print "Content-Type: image/png\n\n";
90 $title .= " $g->{Units}" if $g->{Units};
91 unshift @args, '-t', $title;
93 exec qw(rrdtool graph - -a PNG --full-size-mode -w 380 -h 200), @args;
97 my $detail= param('detail');
99 die unless $graphs{$detail};
100 print header(), start_html(), h1("$detail graphs");
101 foreach my $end (qw(3600 86400 604800 2419200)) {
102 print "<img src=\"$self?graph=$detail&end=$end\">\n";
108 if (param('debug')) {
110 print Dumper(\%graphs);
114 print header(), start_html();
117 foreach my $gname (@graphs) {
118 print "<a href=\"$self?detail=$gname\">"; #,h2($gname),"</a>";
119 print "<img src=\"$self?graph=$gname\"></a>\n";