X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=contrib%2Fcollectd2html.pl;h=511b3f9d585d0a8ad2bfb1ea79e396fa7b8fdbac;hb=b1b0aa549005c62b0e4651053198693e33ea84f0;hp=32d6305592981b7f27ace786051834f52c42fc72;hpb=917abf10c462903cd3bb37faadba68f91f5ca8b1;p=collectd.git
diff --git a/contrib/collectd2html.pl b/contrib/collectd2html.pl
index 32d63055..511b3f9d 100644
--- a/contrib/collectd2html.pl
+++ b/contrib/collectd2html.pl
@@ -41,20 +41,34 @@ 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 $DIR = "/var/lib/collectd";
+my $HOST = undef;
+my $IMG_FMT = "PNG";
+my $RECURSIVE = 1;
GetOptions (
- "host=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);
+my @tmp = `/bin/hostname -f`; chomp(@tmp);
$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";
+my $HTML = "${HOST}.xhtml";
################################################################################
#
@@ -104,54 +118,70 @@ open(OUT, ">$HTML");
my $title="Rrd plot for $HOST";
print OUT <
+
END
foreach my $bn (@rrds){
- my $cleaned_bn = $bn; $cleaned_bn =~ s/%/_/g;
+ my $cleaned_bn = $bn;
+ $cleaned_bn =~ tr/%\//__/;
print OUT <$title
-$title
+$bn
+$bn
END
# graph various ranges
- foreach my $span qw(1hour 1day 1week 1month){
- my $png = "$IMG_DIR/${bn}-$span.png";
+ 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 $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 <