aboutsummaryrefslogtreecommitdiffstats
path: root/stats.pl
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2015-02-11 21:36:19 +0100
committerMarius Halden <marius.h@lden.org>2015-02-11 21:36:19 +0100
commite750e9635f5ade0754a8cbac821570da2f80df93 (patch)
tree68ef81fb2f689510d2c5a6476a78fe61c47b8613 /stats.pl
parentdba7f8c452ae3d0950e759c92c38fecdb18505f2 (diff)
downloadappdrift-stats-e750e9635f5ade0754a8cbac821570da2f80df93.tar.gz
appdrift-stats-e750e9635f5ade0754a8cbac821570da2f80df93.tar.bz2
appdrift-stats-e750e9635f5ade0754a8cbac821570da2f80df93.tar.xz
So many changes I have no idea what the log should say :(
Diffstat (limited to 'stats.pl')
-rwxr-xr-xstats.pl335
1 files changed, 163 insertions, 172 deletions
diff --git a/stats.pl b/stats.pl
index cb65417..726ceea 100755
--- a/stats.pl
+++ b/stats.pl
@@ -19,6 +19,7 @@ my @group_colors = qw(
000066 3366CC CC00CC 800000 CC0099
);
+# HTTP get from url through proxy
sub proxy_get {
my $remote = shift;
@@ -30,6 +31,18 @@ sub proxy_get {
return $response->content;
}
+# Check if string is in array
+sub in_array {
+ my $str = shift;
+ my $arr = shift;
+
+ for my $val (@{$arr}) {
+ return 1 if ($str eq $val);
+ }
+
+ return 0;
+}
+
my $groups = {};
my @content = split /^-+$/m, get($score_url);
@@ -90,19 +103,36 @@ for my $group (sort keys %$groups) {
}
}
- $groups->{$group}->{'users'} = defined($users) ? $users : 0;
- $groups->{$group}->{'posts'} = defined($posts) ? $posts : 0;
- $groups->{$group}->{'comments'} = defined($comments) ? $comments : 0;
+ $groups->{$group}->{'users'} = $users; #defined($users) ? $users : 0;
+ $groups->{$group}->{'posts'} = $posts; #defined($posts) ? $posts : 0;
+ $groups->{$group}->{'comments'} = $comments; #defined($comments) ? $comments : 0;
}
-my %rrd_groups = ();
-my %positions = ();
-my %balance = ();
-my %www_users = ();
-my %posts = ();
-my %comments = ();
+my $group_info = {
+# rrd_groups => {},
+# position => {},
+# balance => {},
+# uptime => {},
+# downtime => {},
+# maintenance => {},
+
+# users => {},
+# posts => {},
+# comments => {},
+ };
+
+my %g_rrd_info = (
+ destination => "$rrd_path/graph",
+ periods => [ qw(day week month) ],
+ interlaced => "",
+ extended_legend => "true",
+ timestamp => "both",
+ );
for my $group (sort keys %$groups) {
+ my %rrd_info = %g_rrd_info;
+ $rrd_info{'destination'} = "$rrd_path/graph/$group";
+
my $uptime_rrd = RRD::Simple->new( file => "$rrd_path/rrd/$group-uptime.rrd" );
my $users_rrd = RRD::Simple->new( file => "$rrd_path/rrd/$group-users.rrd" );
@@ -134,288 +164,249 @@ for my $group (sort keys %$groups) {
comments => $groups->{$group}->{'comments'},
);
- unless ( -d "$rrd_path/graph/score/$group" ) {
- mkdir "$rrd_path/graph/score/$group";
- }
-
- unless ( -d "$rrd_path/graph/users/$group" ) {
- mkdir "$rrd_path/graph/users/$group";
+ unless ( -d "$rrd_path/graph/$group" ) {
+ mkdir "$rrd_path/graph/$group";
}
- my %times_rtn = $uptime_rrd->graph(
- destination => "$rrd_path/graph/score/$group",
+ $uptime_rrd->graph(
+ %rrd_info,
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/score/$group",
+ $uptime_rrd->graph(
+ %rrd_info,
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/score/$group",
+ $uptime_rrd->graph(
+ %rrd_info,
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/score/$group",
+ $uptime_rrd->graph(
+ %rrd_info,
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",
);
- my %all_stats_rtn = $users_rrd->graph(
- destination => "$rrd_path/graph/users/$group",
- basename => "all",
+ $users_rrd->graph(
+ %rrd_info,
+ basename => "all-user-stats",
sources => [ qw(users posts comments) ],
source_colors => [ qw(00CC00 0000FF FF0000) ],
- periods => [ qw(day week month) ],
title => "Users/Posts/Comments for $group",
vertical_label => "Count",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
- my %users_rtn = $users_rrd->graph(
- destination => "$rrd_path/graph/users/$group",
+ $users_rrd->graph(
+ %rrd_info,
basename => "users",
sources => [ qw(users) ],
source_colors => [ qw(00CC00) ],
- periods => [ qw(day week month) ],
title => "User count for $group",
vertical_label => "Nr. of users",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
- my %posts_rtn = $users_rrd->graph(
- destination => "$rrd_path/graph/users/$group",
+ $users_rrd->graph(
+ %rrd_info,
basename => "posts",
sources => [ qw(posts) ],
source_colors => [ qw(0000FF) ],
- periods => [ qw(day week month) ],
title => "Post count for $group",
vertical_label => "Nr. of posts",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
- my %comments_rtn = $users_rrd->graph(
- destination => "$rrd_path/graph/users/$group",
+ $users_rrd->graph(
+ %rrd_info,
basename => "comments",
sources => [ qw(comments) ],
source_colors => [ qw(FF0000) ],
- periods => [ qw(day week month) ],
title => "Comment count for $group",
vertical_label => "Nr. of comments",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
- $rrd_groups{$group} = "GAUGE";
- $positions{$group} = $groups->{$group}->{'position'};
- $balance{$group} = $groups->{$group}->{'balance'};
- $www_users{$group} = $groups->{$group}->{'users'};
- $posts{$group} = $groups->{$group}->{'posts'};
- $comments{$group} = $groups->{$group}->{'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'};
}
+## Score related
my $pos_rrd = "$rrd_path/rrd/positions.rrd";
my $bal_rrd = "$rrd_path/rrd/balance.rrd";
-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 $upt_rrd = "$rrd_path/rrd/uptime.rrd";
+my $dwn_rrd = "$rrd_path/rrd/downtime.rrd";
+my $mnt_rrd = "$rrd_path/rrd/maintenance.rrd";
my $position_rrd = RRD::Simple->new( file => "$pos_rrd" );
my $balance_rrd = RRD::Simple->new( file => "$bal_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 $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" );
-$position_rrd->create( %rrd_groups ) unless ( -f "$pos_rrd" );
-$balance_rrd->create( %rrd_groups ) unless ( -f "$bal_rrd" );
-$user_rrd->create( %rrd_groups ) unless ( -f "$usr_rrd" );
-$post_rrd->create( %rrd_groups ) unless ( -f "$pst_rrd" );
-$comment_rrd->create( %rrd_groups ) unless ( -f "$cmt_rrd" );
+$position_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$pos_rrd" );
+$balance_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$bal_rrd" );
+$uptime_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$upt_rrd" );
+$downtime_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$dwn_rrd" );
+$maint_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$mnt_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);
- }
+my @upt_sources = $uptime_rrd->sources("$upt_rrd");
+my @dwn_sources = $downtime_rrd->sources("$dwn_rrd");
+my @mnt_sources = $maint_rrd->sources("$mnt_rrd");
- $balance_rrd->add_source("$bal_rrd", $group => $rrd_groups{$group});
-}
+## User related
+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 @usr_sources = $user_rrd->sources("$usr_rrd");
-usr_sources: for my $group (keys %www_users) {
- for my $source (@usr_sources) {
- next usr_sources if ($source eq $group);
- }
+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" );
- $user_rrd->add_source("$usr_rrd", $group => $rrd_groups{$group});
-}
+$user_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$usr_rrd" );
+$post_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$pst_rrd" );
+$comment_rrd->create(%{$group_info->{'rrd_groups'}}) unless ( -f "$cmt_rrd" );
+my @usr_sources = $user_rrd->sources("$usr_rrd");
my @pst_sources = $user_rrd->sources("$pst_rrd");
-pst_sources: for my $group (keys %posts) {
- for my $source (@pst_sources) {
- next pst_sources if ($source eq $group);
- }
-
- $post_rrd->add_source("$pst_rrd", $group => $rrd_groups{$group});
-}
-
my @cmt_sources = $comment_rrd->sources("$cmt_rrd");
-cmt_sources: for my $group (keys %posts) {
- for my $source (@cmt_sources) {
- next cmt_sources if ($source eq $group);
- }
- $comment_rrd->add_source("$cmt_rrd", $group => $rrd_groups{$group});
+for my $group (keys %{$group_info->{'rrd_groups'}}) {
+ $position_rrd->add_source("$pos_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@pos_sources));
+ $balance_rrd->add_source("$bal_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@bal_sources));
+ $uptime_rrd->add_source("$upt_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@upt_sources));
+ $downtime_rrd->add_source("$dwn_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@dwn_sources));
+ $maint_rrd->add_source("$mnt_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@mnt_sources));
+
+ $user_rrd->add_source("$usr_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@usr_sources));
+ $post_rrd->add_source("$pst_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@pst_sources));
+ $comment_rrd->add_source("$cmt_rrd", $group => $group_info->{'rrd_groups'}->{$group}) unless (in_array($group, \@cmt_sources));
}
-$position_rrd->update( %positions );
-$balance_rrd->update( %balance );
-$user_rrd->update( %www_users );
-$post_rrd->update( %posts );
-$comment_rrd->update( %comments );
+$position_rrd->update(%{$group_info->{'position'}});
+$balance_rrd->update(%{$group_info->{'balance'}});
+$uptime_rrd->update(%{$group_info->{'uptime'}});
+$downtime_rrd->update(%{$group_info->{'downtime'}});
+$maint_rrd->update(%{$group_info->{'maintenance'}});
+$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;
-my %position_rtn = $position_rrd->graph(
- destination => "$rrd_path/graph/score",
+$g_rrd_info{'sources'} = [ @group_names ];
+$g_rrd_info{'source_colors'} = [ @group_colors ];
+
+$position_rrd->graph(
+ %g_rrd_info,
basename => "positions",
- 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/score",
+$balance_rrd->graph(
+ %g_rrd_info,
basename => "balance",
- periods => [ qw(day week month) ],
- sources => [ @group_names ],
- source_colors => [ @group_colors ],
title => "Balances",
vertical_label => "Balance",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
-my %users_rtn = $user_rrd->graph(
- destination => "$rrd_path/graph/users",
+$uptime_rrd->graph(
+ %g_rrd_info,
+ basename => "uptime",
+ title => "Uptime per group",
+ vertical_label => "Uptime/seconds",
+ );
+
+$downtime_rrd->graph(
+ %g_rrd_info,
+ basename => "downtime",
+ title => "Downtime per group",
+ vertical_label => "Downtime/seconds",
+ );
+
+$maint_rrd->graph(
+ %g_rrd_info,
+ basename => "maintenance",
+ title => "Maintenance per group",
+ vertical_label => "Maintenance/seconds",
+ );
+
+$uptime_rrd->graph(
+ %g_rrd_info,
+ basename => "uptime",
+ title => "Uptime per group",
+ vertical_label => "Uptime/seconds",
+ );
+
+
+$user_rrd->graph(
+ %g_rrd_info,
basename => "users",
- periods => [ qw(day week month) ],
- sources => [ @group_names ],
- source_colors => [ @group_colors ],
title => "Number of users per group",
vertical_label => "Nr. of users",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
-my %posts_rtn = $post_rrd->graph(
- destination => "$rrd_path/graph/users",
+$post_rrd->graph(
+ %g_rrd_info,
basename => "posts",
- periods => [ qw(day week month) ],
- sources => [ @group_names ],
- source_colors => [ @group_colors ],
title => "Number of posts per group",
vertical_label => "Nr. of posts",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
-my %comments_rtn = $comment_rrd->graph(
- destination => "$rrd_path/graph/users",
+$comment_rrd->graph(
+ %g_rrd_info,
basename => "comments",
- periods => [ qw(day week month) ],
- sources => [ @group_names ],
- source_colors => [ @group_colors ],
title => "Number of comments per group",
vertical_label => "Nr. of comments",
- interlaced => "",
- extended_legend => "true",
- timestamp => "both",
);
+delete $g_rrd_info{'sources'};
+delete $g_rrd_info{'source_colors'};
+
for my $group (@group_names) {
- my %grp_bal = $balance_rrd->graph(
- destination => "$rrd_path/graph/score/$group",
+ my %rrd_info = %g_rrd_info;
+ $rrd_info{'destination'} = "$rrd_path/graph/$group";
+
+ $balance_rrd->graph(
+ %rrd_info,
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/score/$group",
+ $position_rrd->graph(
+ %rrd_info,
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"
);
}