aboutsummaryrefslogtreecommitdiffstats
path: root/stats.pl
diff options
context:
space:
mode:
Diffstat (limited to 'stats.pl')
-rwxr-xr-xstats.pl76
1 files changed, 34 insertions, 42 deletions
diff --git a/stats.pl b/stats.pl
index ef1261b..da1390e 100755
--- a/stats.pl
+++ b/stats.pl
@@ -43,7 +43,8 @@ sub in_array {
return 0;
}
-my $groups = {};
+my $group_info = {};
+my @group_names = ();
my @content = split /^-+$/m, get($score_url);
shift @content;
@@ -74,20 +75,24 @@ for my $section (@content) {
}
}
- $groups->{$user} = {
- position => $position,
- balance => $balance,
- server => $endpoint,
- time_up => $time_up,
- time_maint => $time_maint,
- time_down => $time_down,
- }
+ $group_info->{'rrd_groups'}->{$user} = "GAUGE";
+ $group_info->{'position'}->{$user} = $position;
+ $group_info->{'balance'}->{$user} = $balance;
+ $group_info->{'uptime'}->{$user} = $time_up;
+ $group_info->{'downtime'}->{$user} = $time_down;
+ $group_info->{'maintenance'}->{$user} = $time_maint;
+ $group_info->{'server'}->{$user} = $endpoint;
+
+ push @group_names, $user;
}
-for my $group (sort keys %$groups) {
+@group_names = sort @group_names;
+$#group_colors = $#group_names;
+
+for my $group (@group_names) {
my ($users, $posts, $comments) = (undef);
- my $content = proxy_get("http://".$groups->{$group}->{'server'});
+ my $content = proxy_get("http://".$group_info->{'server'}->{$group});
for my $line (split /\n/, $content) {
last if (defined($users) && defined($posts) && defined($comments));
@@ -103,12 +108,11 @@ for my $group (sort keys %$groups) {
}
}
- $groups->{$group}->{'users'} = $users;
- $groups->{$group}->{'posts'} = $posts;
- $groups->{$group}->{'comments'} = $comments;
+ $group_info->{'users'}->{$group} = $users;
+ $group_info->{'posts'}->{$group} = $posts;
+ $group_info->{'comments'}->{$group} = $comments;
}
-my $group_info = {};
my %g_rrd_info = (
destination => "$rrd_path/graph",
periods => [ qw(day week month) ],
@@ -117,7 +121,7 @@ my %g_rrd_info = (
timestamp => "both",
);
-for my $group (sort keys %$groups) {
+for my $group (@group_names) {
my %rrd_info = %g_rrd_info;
$rrd_info{'destination'} = "$rrd_path/graph/$group";
@@ -133,15 +137,15 @@ for my $group (sort keys %$groups) {
unless ( -f "$rrd_path/rrd/$group-users.rrd" );
$uptime_rrd->update(
- uptime => $groups->{$group}->{'time_up'},
- maintenance => $groups->{$group}->{'time_maint'},
- downtime => $groups->{$group}->{'time_down'},
+ uptime => $group_info->{'uptime'}->{$group},
+ maintenance => $group_info->{'maintenance'}->{$group},
+ downtime => $group_info->{'downtime'}->{$group},
);
$users_rrd->update(
- users => $groups->{$group}->{'users'},
- posts => $groups->{$group}->{'posts'},
- comments => $groups->{$group}->{'comments'},
+ users => $group_info->{'users'}->{$group},
+ posts => $group_info->{'posts'}->{$group},
+ comments => $group_info->{'comments'}->{$group},
);
$uptime_rrd->graph(
@@ -216,15 +220,6 @@ for my $group (sort keys %$groups) {
vertical_label => "Nr. of comments",
);
- $group_info->{'rrd_groups'}->{$group} = "GAUGE";
- $group_info->{'position'}->{$group} = $groups->{$group}->{'position'};
- $group_info->{'balance'}->{$group} = $groups->{$group}->{'balance'};
- $group_info->{'uptime'}->{$group} = $groups->{$group}->{'time_up'};
- $group_info->{'downtime'}->{$group} = $groups->{$group}->{'time_down'};
- $group_info->{'maintenance'}->{$group} = $groups->{$group}->{'time_maint'};
- $group_info->{'users'}->{$group} = $groups->{$group}->{'users'};
- $group_info->{'posts'}->{$group} = $groups->{$group}->{'posts'};
- $group_info->{'comments'}->{$group} = $groups->{$group}->{'comments'};
}
my $pos_rrd = "$rrd_path/rrd/positions.rrd";
@@ -236,14 +231,14 @@ my $usr_rrd = "$rrd_path/rrd/users.rrd";
my $pst_rrd = "$rrd_path/rrd/posts.rrd";
my $cmt_rrd = "$rrd_path/rrd/comments.rrd";
-my $position_rrd = RRD::Simple->new( file => "$pos_rrd" );
-my $balance_rrd = RRD::Simple->new( file => "$bal_rrd" );
-my $uptime_rrd = RRD::Simple->new( file => "$upt_rrd" );
-my $downtime_rrd = RRD::Simple->new( file => "$dwn_rrd" );
-my $maint_rrd = RRD::Simple->new( file => "$mnt_rrd" );
-my $user_rrd = RRD::Simple->new( file => "$usr_rrd" );
-my $post_rrd = RRD::Simple->new( file => "$pst_rrd" );
-my $comment_rrd = RRD::Simple->new( file => "$cmt_rrd" );
+my $position_rrd = RRD::Simple->new( file => "$pos_rrd" );
+my $balance_rrd = RRD::Simple->new( file => "$bal_rrd" );
+my $uptime_rrd = RRD::Simple->new( file => "$upt_rrd" );
+my $downtime_rrd = RRD::Simple->new( file => "$dwn_rrd" );
+my $maint_rrd = RRD::Simple->new( file => "$mnt_rrd" );
+my $user_rrd = RRD::Simple->new( file => "$usr_rrd" );
+my $post_rrd = RRD::Simple->new( file => "$pst_rrd" );
+my $comment_rrd = RRD::Simple->new( file => "$cmt_rrd" );
$position_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$pos_rrd" );
$balance_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$bal_rrd" );
@@ -283,9 +278,6 @@ $user_rrd->update(%{$group_info->{'users'}});
$post_rrd->update(%{$group_info->{'posts'}});
$comment_rrd->update(%{$group_info->{'comments'}});
-my @group_names = sort(keys(%$groups));
-$#group_colors = $#group_names;
-
$g_rrd_info{'sources'} = [ @group_names ];
$g_rrd_info{'source_colors'} = [ @group_colors ];