3 ################################################################################
8 # Generate an html page with all rrd data gathered by collectd.
13 # When run on <host>, it generated <host>.html and <host>.dir, the latter
14 # containing all necessary images.
17 # Copyright 2006 Vincent Stehlé <vincent.stehle@free.fr>
19 # This program is free software; you can redistribute it and/or modify
20 # it under the terms of the GNU General Public License as published by
21 # the Free Software Foundation; either version 2 of the License, or
22 # (at your option) any later version.
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 ################################################################################
37 use Fatal qw(open close);
40 my $DIR = "/var/lib/collectd";
41 my @COLORS = (0xff7777, 0x7777ff, 0x55ff55, 0xffcc77, 0xff77ff, 0x77ffff,
43 my @tmp = `/bin/hostname`; chomp(@tmp);
45 my $IMG_DIR = "${HOST}.dir";
46 my $HTML = "${HOST}.html";
48 ################################################################################
53 # Fade a color's component to the white.
55 ################################################################################
59 return (($component + 255 * 5) / 6);
62 ################################################################################
67 # Fade a color to the white.
69 ################################################################################
77 my $component = (($color >> $shft) & 255);
78 $r |= (fade_component($component) << $shft);
84 ################################################################################
88 ################################################################################
89 system("rm -fR $IMG_DIR");
90 system("mkdir -p $IMG_DIR");
93 my $title="Rrd plot for $HOST";
96 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
97 "http://www.w3.org/TR/html4/loose.dtd">
100 <title>$title</title>
106 # list interesting rrd
108 my @list = `ls $DIR/*.rrd`; chomp(@list);
110 foreach my $rrd (sort @list){
111 my $bn = basename($rrd);
118 <A name="top"></A><H1>$title</H1>
122 foreach my $bn (@rrds){
123 my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
125 <A href="#$cleaned_bn">$bn</A>
133 # graph interesting rrd
134 foreach my $bn (@rrds){
137 my $rrd = "$DIR/${bn}.rrd";
138 my $cmd = "rrdtool info $rrd |grep 'ds\\[' |sed 's/^ds\\[//'"
139 ." |sed 's/\\].*//' |sort |uniq";
140 my @dss = `$cmd`; chomp(@dss);
146 foreach my $ds (@dss){
147 $defs .= " DEF:${ds}_avg=$rrd:$ds:AVERAGE"
148 ." DEF:${ds}_max=$rrd:$ds:MAX ";
154 foreach my $ds (@dss){
155 my $color = $COLORS[$i % scalar(@COLORS)]; $i++;
156 my $faded_color = fade_color($color);
157 $defs .= sprintf(" AREA:${ds}_max#%06x ", $faded_color);
163 foreach my $ds (@dss){
164 my $color = $COLORS[$i % scalar(@COLORS)]; $i++;
165 $defs .= sprintf(" LINE2:${ds}_avg#%06x:$ds"
166 ." GPRINT:${ds}_avg:AVERAGE:%%5.1lf%%sAvg"
167 ." GPRINT:${ds}_max:MAX:%%5.1lf%%sMax"
171 my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
173 <A name="$cleaned_bn"></A><H1>$bn</H1>
176 # graph various ranges
177 foreach my $span qw(1hour 1day 1week 1month){
178 my $png = "$IMG_DIR/${bn}-$span.png";
180 my $cmd = "rrdtool graph $png"
181 ." -t \"$bn $span\" --imgformat PNG --width 600 --height 100"
182 ." --start now-$span --end now --interlaced"
183 ." $defs >/dev/null 2>&1";
186 my $cleaned_png = $png; $cleaned_png =~ s/%/%25/g;
188 <P><IMG src="$cleaned_png" alt="${bn} $span"></P>
193 <A href="#top">[top]</A>