X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fcollectd2html.pl;h=7953d67ccab85b6cca88c54a9e906dce6c58a4dd;hb=3ab61b1ff7e5c259256660a39c3e83f13a9a70f6;hp=da143d700b3d65f41f51a84106264ebb3845cc2d;hpb=58ecdb7ff9a4d90e87daecca05b9cb4a43070fd7;p=collectd.git diff --git a/contrib/collectd2html.pl b/contrib/collectd2html.pl index da143d70..7953d67c 100644 --- a/contrib/collectd2html.pl +++ b/contrib/collectd2html.pl @@ -16,6 +16,9 @@ # # Copyright 2006 Vincent Stehlé # +# Patch to configure the data directory and hostname by Eddy Petrisor +# . +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -38,18 +41,32 @@ use Fatal qw(open close); use File::Basename; use Getopt::Long qw(:config no_ignore_case bundling pass_through); -my $DIR = "/var/lib/collectd"; -my $HOST = "_UNDEFINED_"; +my $DIR = "/var/lib/collectd"; +my $HOST = undef; +my $IMG_FMT = "PNG"; +my $RECURSIVE = 0; GetOptions ( - "host-is=s" => \$HOST, - "data-dir=s" => \$DIR + "host=s" => \$HOST, + "data-dir=s" => \$DIR, + "image-format=s" => \$IMG_FMT, + "recursive" => \$RECURSIVE ); +if (($DIR !~ m/\/rrd\/?$/) && (-d "$DIR/rrd")) { + $DIR .= "/rrd"; +} + +if (defined($HOST) && ($DIR !~ m/\/$HOST\/?$/) && (-d "$DIR/$HOST")) { + $DIR .= "/$HOST"; +} + my @COLORS = (0xff7777, 0x7777ff, 0x55ff55, 0xffcc77, 0xff77ff, 0x77ffff, 0xffff77, 0x55aaff); my @tmp = `/bin/hostname`; chomp(@tmp); -$HOST = $tmp[0] if ( $HOST =~ /_UNDEFINED_/ ); +$HOST = $tmp[0] if (! defined $HOST); +my $svg_p = ($IMG_FMT eq "SVG"); +my $IMG_SFX = $svg_p ? ".svg" : ".png"; my $IMG_DIR = "${HOST}.dir"; my $HTML = "${HOST}.html"; @@ -113,12 +130,19 @@ END # list interesting rrd my @rrds; -my @list = `ls $DIR/*.rrd`; chomp(@list); +my @list; + +if ($RECURSIVE) { + @list = `find $DIR -type f -name '*.rrd'`; +} +else { + @list = `ls $DIR/*.rrd`; +} +chomp(@list); foreach my $rrd (sort @list){ - my $bn = basename($rrd); - $bn =~ s/\.rrd$//; - push(@rrds, $bn); + $rrd =~ m/^$DIR\/(.*)\.rrd$/; + push(@rrds, $1); } # table of contents @@ -128,7 +152,8 @@ print OUT <$bn END @@ -139,16 +164,17 @@ print OUT <

$bn

END # graph various ranges foreach my $span qw(1hour 1day 1week 1month){ - my $png = "$IMG_DIR/${bn}-$span.png"; + system("mkdir -p $IMG_DIR/" . dirname($bn)); + my $img = "$IMG_DIR/${bn}-$span$IMG_SFX"; - my $cmd = "rrdtool graph $png" - ." -t \"$bn $span\" --imgformat PNG --width 600 --height 100" + my $cmd = "rrdtool graph $img" + ." -t \"$bn $span\" --imgformat $IMG_FMT --width 600 --height 100" ." --start now-$span --end now --interlaced" ." $defs >/dev/null 2>&1"; system($cmd); - my $cleaned_png = $png; $cleaned_png =~ s/%/%25/g; - print OUT <${bn} $span

+ my $cleaned_img = $img; $cleaned_img =~ s/%/%25/g; + if (! $svg_p) { + print OUT <${bn} $span

+END + } else { + print OUT < + ${bn} $span

END + } } print OUT <