From 4c7e56830fbabdc909e5f24508de58e22f3fcd21 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Mon, 22 Jun 2009 16:02:24 +0200 Subject: [PATCH] collectd2html.pl: Added --recursive command line option. This option may be used to recursively scan the specified directory for RRD files. This way, the script works reasonably well with collectd 4. Thanks to 'ABL ' for providing an initial patch in Debian bug #482185. --- contrib/collectd2html.pl | 59 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/contrib/collectd2html.pl b/contrib/collectd2html.pl index ab22bf97..7953d67c 100644 --- a/contrib/collectd2html.pl +++ b/contrib/collectd2html.pl @@ -41,16 +41,26 @@ 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 = undef; -my $IMG_FMT = "PNG"; +my $DIR = "/var/lib/collectd"; +my $HOST = undef; +my $IMG_FMT = "PNG"; +my $RECURSIVE = 0; GetOptions ( - "host=s" => \$HOST, - "data-dir=s" => \$DIR, - "image-format=s" => \$IMG_FMT + "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); @@ -120,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 @@ -135,7 +152,8 @@ print OUT <$bn END @@ -146,16 +164,17 @@ print OUT <

$bn

END # graph various ranges foreach my $span qw(1hour 1day 1week 1month){ + system("mkdir -p $IMG_DIR/" . dirname($bn)); my $img = "$IMG_DIR/${bn}-$span$IMG_SFX"; my $cmd = "rrdtool graph $img" -- 2.11.0