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 # Patch to configure the data directory and hostname by Eddy Petrisor
20 # <eddy.petrisor@gmail.com>.
22 # This program is free software; you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24 # the Free Software Foundation; either version 2 of the License, or
25 # (at your option) any later version.
27 # This program is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write to the Free Software
34 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 ################################################################################
40 use Fatal qw(open close);
42 use Getopt::Long qw(:config no_ignore_case bundling pass_through);
44 my $DIR = "/var/lib/collectd";
52 my @COLORS = (0xff7777, 0x7777ff, 0x55ff55, 0xffcc77, 0xff77ff, 0x77ffff,
54 my @tmp = `/bin/hostname`; chomp(@tmp);
55 $HOST = $tmp[0] if (! defined $HOST);
56 my $IMG_DIR = "${HOST}.dir";
57 my $HTML = "${HOST}.html";
59 ################################################################################
64 # Fade a color's component to the white.
66 ################################################################################
70 return (($component + 255 * 5) / 6);
73 ################################################################################
78 # Fade a color to the white.
80 ################################################################################
88 my $component = (($color >> $shft) & 255);
89 $r |= (fade_component($component) << $shft);
95 ################################################################################
99 ################################################################################
100 system("rm -fR $IMG_DIR");
101 system("mkdir -p $IMG_DIR");
104 my $title="Rrd plot for $HOST";
107 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
108 "http://www.w3.org/TR/html4/loose.dtd">
111 <title>$title</title>
117 # list interesting rrd
119 my @list = `ls $DIR/*.rrd`; chomp(@list);
121 foreach my $rrd (sort @list){
122 my $bn = basename($rrd);
129 <A name="top"></A><H1>$title</H1>
133 foreach my $bn (@rrds){
134 my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
136 <A href="#$cleaned_bn">$bn</A>
144 # graph interesting rrd
145 foreach my $bn (@rrds){
148 my $rrd = "$DIR/${bn}.rrd";
149 my $cmd = "rrdtool info $rrd |grep 'ds\\[' |sed 's/^ds\\[//'"
150 ." |sed 's/\\].*//' |sort |uniq";
151 my @dss = `$cmd`; chomp(@dss);
157 foreach my $ds (@dss){
158 $defs .= " DEF:${ds}_avg=$rrd:$ds:AVERAGE"
159 ." DEF:${ds}_max=$rrd:$ds:MAX ";
165 foreach my $ds (@dss){
166 my $color = $COLORS[$i % scalar(@COLORS)]; $i++;
167 my $faded_color = fade_color($color);
168 $defs .= sprintf(" AREA:${ds}_max#%06x ", $faded_color);
174 foreach my $ds (@dss){
175 my $color = $COLORS[$i % scalar(@COLORS)]; $i++;
176 $defs .= sprintf(" LINE2:${ds}_avg#%06x:$ds"
177 ." GPRINT:${ds}_avg:AVERAGE:%%5.1lf%%sAvg"
178 ." GPRINT:${ds}_max:MAX:%%5.1lf%%sMax"
182 my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
184 <A name="$cleaned_bn"></A><H1>$bn</H1>
187 # graph various ranges
188 foreach my $span qw(1hour 1day 1week 1month){
189 my $png = "$IMG_DIR/${bn}-$span.png";
191 my $cmd = "rrdtool graph $png"
192 ." -t \"$bn $span\" --imgformat PNG --width 600 --height 100"
193 ." --start now-$span --end now --interlaced"
194 ." $defs >/dev/null 2>&1";
197 my $cleaned_png = $png; $cleaned_png =~ s/%/%25/g;
199 <P><IMG src="$cleaned_png" alt="${bn} $span"></P>
204 <A href="#top">[top]</A>