diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-03-10 09:00:06 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-03-10 09:00:06 +0100 |
commit | a87c139271b5e9c50bf93114472019ad43b0893a (patch) | |
tree | 375e543db0132826839ff9e89017b5f1fe8773d2 | |
parent | 3ae14d47f91f36bacdfe604414f1186f375ac8a0 (diff) |
add statistics for munin
-rwxr-xr-x | munin-stats.pl | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/munin-stats.pl b/munin-stats.pl new file mode 100755 index 0000000..b476ec2 --- /dev/null +++ b/munin-stats.pl @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use 5.020; + +use DateTime; +use DBI; + +sub query_to_munin { + my ( $label, $query, @args ) = @_; + + $query->execute(@args); + my $rows = $query->fetchall_arrayref; + if ( @{$rows} ) { + printf( "%s.value %d\n", $label, $rows->[0][0] ); + } +} + +my $dbname = $ENV{TRAVELYNX_DB_FILE} // 'travelynx.sqlite'; +my $dbh = DBI->connect( "dbi:SQLite:dbname=${dbname}", q{}, q{} ); + +my $now = DateTime->now( time_zone => 'Europe/Berlin' ); + +my $checkin_window_query + = $dbh->prepare( +qq{select count(*) from user_actions where action_id = 1 and action_time > ?;} + ); + +query_to_munin( 'reg_user_count', + $dbh->prepare(qq{select count(*) from users where status = 1;}) ); +query_to_munin( 'checkins_24h', $checkin_window_query, + $now->subtract( hours => 24 )->epoch ); +query_to_munin( 'checkins_7d', $checkin_window_query, + $now->subtract( days => 7 )->epoch ); + +$dbh->disconnect; |