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);
# 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
END
foreach my $bn (@rrds){
- my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
+ my $cleaned_bn = $bn;
+ $cleaned_bn =~ tr/%\//__/;
print OUT <<END;
<A href="#$cleaned_bn">$bn</A>
END
END
# graph interesting rrd
-foreach my $bn (@rrds){
+for (my $i = 0; $i < scalar(@rrds); ++$i) {
+ my $bn = $rrds[$i];
print "$bn\n";
- my $rrd = "$DIR/${bn}.rrd";
+ my $rrd = $list[$i];
my $cmd = "rrdtool info $rrd |grep 'ds\\[' |sed 's/^ds\\[//'"
." |sed 's/\\].*//' |sort |uniq";
my @dss = `$cmd`; chomp(@dss);
# all DEF
- my $i = 0;
+ my $j = 0;
my $defs = "";
foreach my $ds (@dss){
}
# all AREA
- $i = 0;
+ $j = 0;
foreach my $ds (@dss){
- my $color = $COLORS[$i % scalar(@COLORS)]; $i++;
+ my $color = $COLORS[$j % scalar(@COLORS)]; $j++;
my $faded_color = fade_color($color);
$defs .= sprintf(" AREA:${ds}_max#%06x ", $faded_color);
}
# all LINE
- $i = 0;
+ $j = 0;
foreach my $ds (@dss){
- my $color = $COLORS[$i % scalar(@COLORS)]; $i++;
+ my $color = $COLORS[$j % scalar(@COLORS)]; $j++;
$defs .= sprintf(" LINE2:${ds}_avg#%06x:$ds"
." GPRINT:${ds}_avg:AVERAGE:%%5.1lf%%sAvg"
." GPRINT:${ds}_max:MAX:%%5.1lf%%sMax"
, $color);
}
- my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
+ my $cleaned_bn = $bn;
+ $cleaned_bn =~ tr/%\//__/;
print OUT <<END;
<A name="$cleaned_bn"></A><H1>$bn</H1>
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"