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
|
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::Simple;
use Data::Dumper;
use RRD::Simple ();
my $rrd_path = "/home/marius/appdrift";
my $score_url = "http://128.39.121.4/purser/scoreboard.txt";
my @group_colors = qw(
003300 003366 0000FF 66FF66 669999
666699 FF99FF 9900CC 660066 660033
FF0000 663300 FFCCCC 66FFFF 993333
000066 3366CC CC00CC 800000 CC0099
);
my $groups = {};
my @content = split /^-+$/m, get($score_url);
shift @content;
for my $section (@content) {
my ($position, $user, $balance, $endpoint, $time_up, $time_maint, $time_down);
for my $line (split /\n/, $section) {
next if (length $line < 1);
if ($line =~ /Position: (.*)/i) {
$position = $1;
} elsif ($line =~ /User: (.*)/i) {
$1 =~ /gruppe(\d+)/;
$user = sprintf("gruppe%02d", $1);
} elsif ($line =~ /Balance: (.*)/i) {
$balance = $1;
} elsif ($line =~ /Endpoint: (.*)/i) {
$endpoint = $1;
} elsif ($line =~ /time_up: (.*)/i) {
$time_up = $1;
} elsif ($line =~ /time_maint: (.*)/i) {
$time_maint = $1;
} elsif ($line =~ /time_down: (.*)/i) {
$time_down = $1;
} else {
print STDERR "Unkown line: \"$line\"";
}
}
$groups->{$user} = {
position => $position,
balance => $balance,
time_up => $time_up,
time_maint => $time_maint,
time_down => $time_down,
}
}
my $position_rrd = RRD::Simple->new( file => "$rrd_path/rrd/positions.rrd" );
my $balance_rrd = RRD::Simple->new( file => "$rrd_path/rrd/balance.rrd" );
my %rrd_groups = ();
my %positions = ();
my %balance = ();
for my $group (sort keys %$groups) {
my $uptime_rrd = RRD::Simple->new( file => "$rrd_path/rrd/$group-uptime.rrd" );
unless ( -f "$rrd_path/rrd/$group-uptime.rrd" ) {
$uptime_rrd->create(
uptime => "GAUGE",
maintenance => "GAUGE",
downtime => "GAUGE",
);
}
$uptime_rrd->update(
uptime => $groups->{$group}->{'time_up'},
maintenance => $groups->{$group}->{'time_maint'},
downtime => $groups->{$group}->{'time_down'},
);
unless ( -d "$rrd_path/graph/$group" ) {
mkdir "$rrd_path/graph/$group";
}
my %times_rtn = $uptime_rrd->graph(
destination => "$rrd_path/graph/$group",
basename => "all-times",
sources => [ qw(uptime maintenance downtime) ],
source_colors => [ qw(00CC00 0000FF FF0000) ],
periods => [ qw(day week month) ],
title => "Time stats group: $group",
vertical_label => "Time/seconds",
interlaced => "",
extended_legend => "true",
timestamp => "both",
);
my %uptime_rtn = $uptime_rrd->graph(
destination => "$rrd_path/graph/$group",
basename => "uptime",
sources => [ qw(uptime) ],
source_colors => [ qw(00CC00) ],
periods => [ qw(day week month) ],
title => "Uptime stats group: $group",
vertical_label => "Time/seconds",
interlaced => "",
extended_legend => "true",
timestamp => "both",
);
my %mainttime_rtn = $uptime_rrd->graph(
destination => "$rrd_path/graph/$group",
basename => "maintenance",
sources => [ qw(maintenance) ],
source_colors => [ qw(0000FF) ],
periods => [ qw(day week month) ],
title => "Uptime stats group: $group",
vertical_label => "Time/seconds",
interlaced => "",
extended_legend => "true",
timestamp => "both",
);
my %downtime_rtn = $uptime_rrd->graph(
destination => "$rrd_path/graph/$group",
basename => "downtime",
sources => [ qw(downtime) ],
source_colors => [ qw(FF0000) ],
periods => [ qw(day week month) ],
title => "Uptime stats group: $group",
vertical_label => "Time/seconds",
interlaced => "",
extended_legend => "true",
timestamp => "both",
);
$rrd_groups{$group} = "GAUGE";
$positions{$group} = $groups->{$group}->{'position'};
$balance{$group} = $groups->{$group}->{'balance'};
}
my $pos_rrd = "$rrd_path/rrd/positions.rrd";
my $bal_rrd = "$rrd_path/rrd/balance.rrd";
$position_rrd->create( %rrd_groups ) unless ( -f "$pos_rrd" );
$balance_rrd->create( %rrd_groups ) unless ( -f "$bal_rrd" );
my @pos_sources = $position_rrd->sources("$pos_rrd");
pos_sources: for my $group (keys %positions) {
for my $source (@pos_sources) {
next pos_sources if ($source eq $group);
}
$position_rrd->add_source("$pos_rrd", $group => $rrd_groups{$group})
}
my @bal_sources = $balance_rrd->sources("$bal_rrd");
bal_sources: for my $group (keys %balance) {
for my $source (@bal_sources) {
next bal_sources if ($source eq $group);
}
$balance_rrd->add_source("$bal_rrd", $group => $rrd_groups{$group})
}
$position_rrd->update( %positions );
$balance_rrd->update( %balance );
my @group_names = sort(keys(%$groups));
$#group_colors = $#group_names;
my %position_rtn = $position_rrd->graph(
destination => "$rrd_path/graph",
periods => [ qw(day week month) ],
sources => [ @group_names ],
source_colors => [ @group_colors ],
title => "Positions",
vertical_label => "Position",
interlaced => "",
extended_legend => "true",
timestamp => "both",
);
my %balance_rtn = $balance_rrd->graph(
destination => "$rrd_path/graph",
periods => [ qw(day week month) ],
sources => [ @group_names ],
source_colors => [ @group_colors ],
title => "Balances",
vertical_label => "Balance",
interlaced => "",
extended_legend => "true",
timestamp => "both",
);
for my $group (@group_names) {
my %grp_bal = $balance_rrd->graph(
destination => "$rrd_path/graph/$group",
basename => "balance",
periods => [ qw(day week month) ],
sources => [ $group ],
source_colors => [ qw(00CC00) ],
title => "Balance for $group",
vertical_label => "Balance",
interlaced => "",
extended_legend => "true",
timestamp => "bith",
);
my %grp_pos = $position_rrd->graph(
destination => "$rrd_path/graph/$group",
basename => "position",
periods => [ qw(day week month) ],
sources => [ $group ],
source_colors => [ qw(00CC00) ],
title => "Position for $group",
vertical_label => "Position",
interlaced => "",
extended_legend => "true",
timestamp => "both"
);
}
|