diff options
author | Marius Halden <marius.h@lden.org> | 2015-02-11 01:55:16 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2015-02-11 01:55:16 +0100 |
commit | c109b7910b110cb45ec9bf2aede67aeb2f8db318 (patch) | |
tree | dc2292cc635542206a42eaa03fece3d392b6ec11 /stats.pl | |
download | appdrift-stats-c109b7910b110cb45ec9bf2aede67aeb2f8db318.tar.gz appdrift-stats-c109b7910b110cb45ec9bf2aede67aeb2f8db318.tar.bz2 appdrift-stats-c109b7910b110cb45ec9bf2aede67aeb2f8db318.tar.xz |
Initial
Diffstat (limited to 'stats.pl')
-rwxr-xr-x | stats.pl | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/stats.pl b/stats.pl new file mode 100755 index 0000000..5c5b407 --- /dev/null +++ b/stats.pl @@ -0,0 +1,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" + ); +} |