summaryrefslogtreecommitdiff
path: root/bin/load-graphs
blob: b3fcef4e4d835f78c45b6bf75b33eaa7f401822b (plain)
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
#!/usr/bin/perl -w

use strict;
use RRDs;
use English;

my $RRDPATH = shift @ARGV;
die ("Usage: $PROGRAM_NAME <rrd dir>\n") if (!defined $RRDPATH || scalar @ARGV > 0);

my $HOSTNAME = `hostname`;


my @MONTH = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};
#my $IMG_URL = 'http://images.noreply.org/load/';
my $IMG_URL = '';
my $NOW = time;
my $GMTIME = gmtime($NOW);
my $START_AT = $NOW-10*30*24*3600;

opendir(D,$RRDPATH) or die ("Cannot opendir $RRDPATH: $!\n");
my @SOURCES = sort {$a cmp $b} grep { /\.rrd$/ && ! /\.pool\.rrd$/ } readdir(D);
@SOURCES = grep {
			my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
			    $atime,$mtime,$ctime,$blksize,$blocks) = stat($RRDPATH.'/'.$_);
			$mtime >= $START_AT;
		} @SOURCES;
closedir(D);

my @params = qw{result/total.png};
push @params, sprintf('-s %s', $START_AT);
#push @params, sprintf('-e %s', $NOW-   2*24*3600);
push @params, sprintf('-t %s', "Network Load");
push @params, sprintf('-v %s', "Messages per day");
push @params, sprintf('-w %d', 600);
push @params, sprintf('-h %d', 400);

my @COLOR = qw{
000000
0000FF
00FF00
00FFFF
FF0000
FF00FF
FFFF00
};
my $coli = 0;
my $first = 1;

my $body;
my $index;
for my $source (@SOURCES) {
	my $def = $source;
	$source = $RRDPATH.'/'.$source;
	$def =~ s/\.rrd$//;
	my $cdef = 'c_'.$def;
	my $color = $COLOR[ ($coli++) % (scalar @COLOR) ];
	my $label = $def;

	push @params , sprintf('DEF:%s=%s:%s:%s', $def          , $source, 'total', 'AVERAGE');
	push @params , sprintf('CDEF:%s=%s'     , $cdef         , $def);
	push @params , sprintf('%s:%s#%s:%s'     , $first ? 'AREA' : 'STACK' , $cdef , $color, $label );
	$first = 0;

	my @this;
	push @this, sprintf('result/%s.png', $def);
	push @this, sprintf('-s %s', $START_AT);
	push @this, sprintf('-t %s', "$def Load");
	push @this, sprintf('-v %s', "Messages per day");

	push @this , sprintf('DEF:%s=%s:%s:%s', 't2'          , $source, 'typeII', 'AVERAGE');
	push @this , sprintf('CDEF:%s=%s'     , 'ct2'         , 't2');
	push @this , sprintf('%s:%s#%s:%s'     , 'AREA' , 'ct2' , '00FF00', 'Type II' );

	push @this , sprintf('DEF:%s=%s:%s:%s', 't1'          , $source, 'typeI', 'AVERAGE');
	push @this , sprintf('CDEF:%s=%s'     , 'ct1'         , 't1');
	push @this , sprintf('%s:%s#%s:%s'     , 'STACK' , 'ct1' , '0000FF', 'Type I' );

	push @this , sprintf('DEF:%s=%s:%s:%s', 'total'          , $source, 'total', 'AVERAGE');
	push @this , sprintf('CDEF:%s=%s'     , 'ctotal'         , 'total');
	push @this , sprintf('%s:%s#%s:%s'     , 'LINE3' , 'ctotal' , '000000', 'total' );

	push @this , sprintf('CDEF:%s=total,0,*,%s,+'     , 'topline'         , '20000');
	push @this , sprintf('CDEF:%s=total,0,*,%s,+'     , 'zeroline'         , '0');
	push @this , sprintf('%s:%s' , 'LINE1' , 'topline' );
	push @this , sprintf('%s:%s' , 'LINE1' , 'zeroline' );

	my ($averages,$xsize,$ysize) = RRDs::graph @this;
	warn RRDs::error if RRDs::error;

	my $poolSize = '';
	my $sourcePoolSize = $RRDPATH.'/'.$def.'.pool.rrd';
	if ( -e $sourcePoolSize ) {
		my $that;

		my @that;
		push @that, sprintf('result/%s.pool.png', $def);
		push @that, sprintf('-s %s', $START_AT);
		push @that, sprintf('-t %s', "$def Pool Size");
		push @that, sprintf('-v %s', "Messages in Pool");

		push @that , sprintf('DEF:%s=%s:%s:%s', 'poolsizeA'          , $sourcePoolSize, 'poolSize', 'AVERAGE');
		push @that , sprintf('CDEF:%s=%s'     , 'cpoolsizeA'         , 'poolsizeA');
		push @that , sprintf('%s:%s#%s:%s'     , 'LINE3' , 'poolsizeA' , '0000FF', 'Pool Size' );

		push @that , sprintf('CDEF:%s=poolsizeA,0,*,%s,+'     , 'topline'         , '400');
		push @that , sprintf('CDEF:%s=poolsizeA,0,*,%s,+'     , 'zeroline'         , '0');
		push @that , sprintf('%s:%s' , 'LINE1' , 'topline' );
		push @that , sprintf('%s:%s' , 'LINE1' , 'zeroline' );
		my ($PSaverages,$PSxsize,$PSysize) = RRDs::graph @that;
		warn RRDs::error if RRDs::error;

		$poolSize = "  <img width=\"$PSxsize\" height=\"$PSysize\" alt=\"Pool Size for $def\" src=\"$IMG_URL$def.pool.png\">";
	}

	$body .= "<h2><a name=\"$def\">$def</a></h2><p><a href=\"#_top\">top</a> | <a href=\"/latency/$def.html\">latency</a><p><img width=\"$xsize\" height=\"$ysize\" alt=\"Load for $def\" src=\"$IMG_URL$def.png\">$poolSize</p>\n";
	$index .= "<li><a href=\"#$def\">$def</a></li>\n";
}
my ($averages,$xsize,$ysize) = RRDs::graph @params;
die RRDs::error if RRDs::error;

my $html = "<html><head><title>Network Load</title></head><body>";
$html .= "<h1><a name=\"_top\">Network Load</a></h1>";
$html .= "<a href=\"../\">..</a><br>\n";
$html .= "<p><img width=\"$xsize\" height=\"$ysize\" src=\"$IMG_URL"."total.png\"></p>";
$html .= "<h1>Single Nodes</h1>";
$html .= "<ul>".$index."</ul>";
$html .= $body;
$html .= "<br><br><br>\n";
$html .= 'Images created with Tobi Oetiker\'s <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">rrdtool</a>'."\n";
$html .= "<hr>\nBuilt at $GMTIME on $HOSTNAME<br>\n";
$html .= "<a href=\"web\@palfrader.org\">Peter Palfrader &lt;web\@palfrader.org&gt;</a>\n";
$html .= "</body></html>\n";

open (F, ">result/index.html") or die ("Cannot open index.html: $!\n");
print F $html;
close F;