This file is indexed.

/usr/share/doc/collectd-core/examples/collectd2html.pl is in collectd-core 5.4.0-3ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/perl

################################################################################
#
# collectd2html.pl
#
# Description:
#   Generate an html page with all rrd data gathered by collectd.
#
# Usage:
#   collectd2html.pl
#
#   When run on <host>, it generated <host>.html and <host>.dir, the latter
#   containing all necessary images.
#
#
# Copyright 2006 Vincent Stehlé <vincent.stehle@free.fr>
#
# Patch to configure the data directory and hostname by Eddy Petrisor
# <eddy.petrisor@gmail.com>.
#
# 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
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
################################################################################

use warnings;
use strict;
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 $RECURSIVE = 1;

GetOptions (
    "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 -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}.xhtml";

################################################################################
#
# fade_component
#
# Description:
#   Fade a color's component to the white.
#
################################################################################
sub fade_component($)
{
	my($component) = @_;
	return (($component + 255 * 5) / 6);
}

################################################################################
#
# fade_color
#
# Description:
#   Fade a color to the white.
#
################################################################################
sub fade_color($)
{
	my($color) = @_;
	my $r = 0;

	for my $i (0 .. 2){
		my $shft = ($i * 8);
		my $component = (($color >> $shft) & 255);
		$r |= (fade_component($component) << $shft);
	}

	return $r;
}

################################################################################
#
# main
#
################################################################################
system("rm -fR $IMG_DIR");
system("mkdir -p $IMG_DIR");
local *OUT;
open(OUT, ">$HTML");
my $title="Rrd plot for $HOST";

print OUT <<END;
<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css" media="screen">
.graph { text-align: center; }
object.graph { width: 670; height: 179; }
</style>
<title>$title</title>
<meta http-equiv="Content-Type"
      content="application/xhtml+xml; charset=us-ascii" />
</head>
<body>
END

# list interesting rrd
my @rrds;
my @list;

if ($RECURSIVE) {
	@list = `find $DIR -type f -name '*.rrd'`;
}
else {
	@list = `ls $DIR/*.rrd`;
}
chomp(@list);

@list = sort @list;
foreach my $rrd (@list){
	$rrd =~ m/^$DIR\/(.*)\.rrd$/;
	push(@rrds, $1);
}

# table of contents
print OUT <<END;
<h1><a id="top">$title</a></h1>
<p>
END

foreach my $bn (@rrds){
	my $cleaned_bn = $bn;
	$cleaned_bn =~ tr/%\//__/;
	print OUT <<END;
<a href="#$cleaned_bn">$bn</a>
END
}

print OUT <<END;
</p>
END

# graph interesting rrd
for (my $i = 0; $i < scalar(@rrds); ++$i) {
	my $bn = $rrds[$i];
	print "$bn\n";

	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 $j = 0;
	my $defs = "";

	foreach my $ds (@dss){
		$defs .= " DEF:${ds}_avg=$rrd:$ds:AVERAGE"
			." DEF:${ds}_max=$rrd:$ds:MAX ";
	}

	# all AREA
	$j = 0;

	foreach my $ds (@dss){
		my $color = $COLORS[$j % scalar(@COLORS)]; $j++;
		my $faded_color = fade_color($color);
		$defs .= sprintf(" AREA:${ds}_max#%06x ", $faded_color);
	}

	# all LINE	
	$j = 0;

	foreach my $ds (@dss){
		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 =~ tr/%\//__/;
	print OUT <<END;
<h2><a id="$cleaned_bn">$bn</a></h2>
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"
			." -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_img = $img; $cleaned_img =~ s/%/%25/g;
		if (! $svg_p) {
			print OUT <<END;
<p class="graph"><img src="$cleaned_img" alt="${bn} $span" /></p>
END
		} else {
			print OUT <<END;
<p class="graph"><object data="$cleaned_img" type="image/svg+xml">
  ${bn} $span</object></p>
END
		}
	}

	print OUT <<END;
<p><a href="#top">[top]</a></p>
END
}

print OUT <<END;
<hr />
<p>
  <a href="http://validator.w3.org/check?uri=referer"><img
     src="http://www.w3.org/Icons/valid-xhtml10"
     alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
</body>
</html>
END

close(OUT);