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);
22 my ($section, $gname, $basis, $args) = @_;
23 $basis->{Args}= $args;
24 $graphs{$section,$gname}= $basis;
25 if (!exists $sections{$section}) {
26 push @sections, $section;
28 push @{ $sections{$section} }, $gname;
31 graph('General', 'Load', { },
33 "DEF:load=$R/load/load.rrd:shortterm:AVERAGE",
34 (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
35 qw(blocked running stopped paging sleeping zombies)),
36 "AREA:running#88f:running processes:STACK",
37 "AREA:blocked#8f8:blocked processes:STACK",
38 "AREA:paging#f88:paging processes:STACK",
42 graph('General', 'Processes', { },
44 (map { "DEF:$_=$R/processes/ps_state-$_.rrd:value:AVERAGE" }
45 qw(blocked running stopped paging sleeping zombies)),
46 "CDEF:busy=0".(join '', map { ",$_,+" } qw(running blocked paging)),
47 "AREA:sleeping#ccc:sleeping:STACK",
48 "AREA:stopped#f00:stopped:STACK",
49 "AREA:zombies#0f0:zombie:STACK",
50 "AREA:busy#f00:busy:STACK",
53 graph('General', 'CPU', { Units => '[%]' },
57 (map { "DEF:$thing$_=$R/cpu-$_/cpu-$thing.rrd:value:AVERAGE" }
59 "CDEF:$thing=0".join('', map { ",$thing$_,+" } (0..7)).",8.0,/";
60 } qw(idle interrupt nice softirq steal system user wait)),
61 "AREA:system#00f:system:STACK",
62 "AREA:wait#f88:wait:STACK",
63 "AREA:nice#ccc:nice:STACK",
64 "AREA:user#080:user:STACK",
65 "AREA:softirq#f0f:softirq:STACK",
66 "AREA:interrupt#ff0:interrupt:STACK",
67 "AREA:steal#0ff:steal:STACK",
70 foreach my $src (<$R/df/df-*.rrd>) {
75 graph('Disk space', $vol, { },
78 (map { "DEF:$_=$src:$_:AVERAGE" } qw(free used)),
79 "AREA:used#000:used:STACK",
80 "AREA:free#88f:free:STACK",
85 print "Content-Type: text/plain\n\n";
88 my $gname= param('graph');
89 my $section= param('section');
90 $section ||= $sections[0];
91 die unless $sections{$section};
94 my $g= $graphs{$section,$gname};
97 my @args= @{ $g->{Args} };
99 my $end= param('end');
101 $end =~ m/^(\d+)$/ or die;
102 unshift @args, qw(--end now --start), "end-${end}s";
104 if (param('debug')) {
105 print((join "\n",@args),"\n"); exit 0;
107 print "Content-Type: image/png\n\n";
110 $title .= " $g->{Units}" if $g->{Units};
111 unshift @args, '-t', $title;
113 exec qw(rrdtool graph - -a PNG --full-size-mode -w 370 -h 200), @args;
119 print header(), start_html($title);
121 foreach my $s2 (@sections) {
123 if ($s2 eq $section) {
124 print "<b>$section</b>";
126 print "<a href=\"$self";
127 if ($s2 ne $sections[0]) { print "?section=$s2"; }
135 my $detail= param('detail');
137 die unless $graphs{$section,$detail};
138 start_page("$detail graphs");
139 foreach my $end (qw(3600 86400 604800 2419200)) {
140 print "<img src=\"$self?graph=$detail§ion=$section&end=$end\">\n";
146 if (param('debug')) {
148 print Dumper(\%graphs);
152 start_page("$section graphs");
154 foreach my $gname (@{ $sections{$section} }) {
155 print "<a href=\"$self?detail=$gname§ion=$section\">"; #,h2($gname),"</a>";
156 print "<img src=\"$self?graph=$gname§ion=$section\"></a>\n";