7 print(header(-status=>500),
15 our $R= '/var/lib/collectd/rrd/chiark.greenend.org.uk';
17 my $self= url(-relative=>1);
19 our (@sections, %sections, %graphs);
21 our @timeranges= (3600, map { $_*86400 } qw(1 7 28), 13*7+1);
24 my ($section, $gname, $basis, $args) = @_;
25 $basis->{Args}= $args;
26 $basis->{Slower}= 0 unless exists $basis->{Slower};
27 $graphs{$section,$gname}= $basis;
28 if (!exists $sections{$section}) {
29 push @sections, $section;
31 push @{ $sections{$section} }, $gname;
34 graph('General', 'Load', { },
36 "DEF:load=$R/load/load.rrd:shortterm:AVERAGE",
37 (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
38 qw(blocked running stopped paging sleeping zombies)),
39 "AREA:running#88f:running processes:STACK",
40 "AREA:blocked#8f8:blocked processes:STACK",
41 "AREA:paging#f88:paging processes:STACK",
45 graph('General', 'Processes', { },
47 (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
48 qw(blocked running stopped paging sleeping zombies)),
49 "CDEF:busy=0".(join '', map { ",$_,+" } qw(running blocked paging)),
50 "AREA:sleeping#ccc:sleeping:STACK",
51 "AREA:stopped#f00:stopped:STACK",
52 "AREA:zombies#0f0:zombie:STACK",
53 "AREA:busy#f00:busy:STACK",
56 graph('General', 'CPU', { Units => '[%]' },
60 (map { "DEF:$thing$_=$R/cpu-$_/cpu-$thing.rrd:value:AVERAGE" }
62 "CDEF:$thing=0".join('', map { ",$thing$_,+" } (0..7)).",8.0,/";
63 } qw(idle interrupt nice softirq steal system user wait)),
64 "AREA:system#00f:system:STACK",
65 "AREA:wait#f88:wait:STACK",
66 "AREA:nice#ccc:nice:STACK",
67 "AREA:user#080:user:STACK",
68 "AREA:softirq#f0f:softirq:STACK",
69 "AREA:interrupt#ff0:interrupt:STACK",
70 "AREA:steal#0ff:steal:STACK",
73 foreach my $src (<$R/df/df-*.rrd>) {
78 graph('Disk space', $vol, {
83 (map { "DEF:$_=$src:$_:AVERAGE" } qw(free used)),
84 "AREA:used#000:used:STACK",
85 "AREA:free#88f:free:STACK",
90 print "Content-Type: text/plain\n\n";
93 my $gname= param('graph');
94 my $section= param('section');
95 $section ||= $sections[0];
96 die unless $sections{$section};
99 my $g= $graphs{$section,$gname};
102 my @args= @{ $g->{Args} };
104 my $end= param('end');
106 $end =~ m/^(\d+)$/ or die;
107 unshift @args, qw(--end now --start), "end-${end}s";
109 if (param('debug')) {
110 print((join "\n",@args),"\n"); exit 0;
112 print "Content-Type: image/png\n\n";
115 $title .= " $g->{Units}" if $g->{Units};
116 unshift @args, '-t', $title;
118 exec qw(rrdtool graph - -a PNG --full-size-mode -w 370 -h 200), @args;
124 print header(), start_html($title);
126 foreach my $s2 (@sections) {
128 if ($s2 eq $section) {
129 print "<b>$section</b>";
131 print "<a href=\"$self";
132 if ($s2 ne $sections[0]) { print "?section=$s2"; }
140 my $detail= param('detail');
142 my $g= $graphs{$section,$detail};
144 start_page("$detail graphs");
145 foreach my $end (@timeranges[$g->{Slower}..$g->{Slower}+3]) {
146 print "<img src=\"$self?graph=$detail§ion=$section&end=$end\">\n";
152 if (param('debug')) {
154 print Dumper(\%graphs);
158 start_page("$section graphs");
160 foreach my $gname (@{ $sections{$section} }) {
161 my $g= $graphs{$section,$gname};
162 print "<a href=\"$self?detail=$gname§ion=$section\">";
163 my $end= $timeranges[$g->{Slower}+1];
164 my $imgurl= "$self?graph=$gname§ion=$section&end=$end";
165 print "<img src=\"$imgurl\"></a>\n";