summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/munin.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx/Command/munin.pm')
-rw-r--r--lib/Travelynx/Command/munin.pm46
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/Travelynx/Command/munin.pm b/lib/Travelynx/Command/munin.pm
index ee509d3..3b6e393 100644
--- a/lib/Travelynx/Command/munin.pm
+++ b/lib/Travelynx/Command/munin.pm
@@ -1,4 +1,8 @@
package Travelynx::Command::munin;
+
+# Copyright (C) 2020-2023 Birte Kristina Friesel
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
use Mojo::Base 'Mojolicious::Command';
use DateTime;
@@ -11,7 +15,7 @@ sub query_to_munin {
my ( $label, $value ) = @_;
if ( defined $value ) {
- printf( "%s.value %d\n", $label, $value );
+ printf( "%s.value %f\n", $label, $value );
}
}
@@ -26,6 +30,19 @@ sub run {
my $checkin_window_query
= qq{select count(*) as count from journeys where checkin_time > to_timestamp(?);};
+ # DateTime's math does not like time zones: When subtracting 7 days from
+ # sun 2am and the previous sunday was the switch from CET to CEST (i.e.,
+ # the switch to daylight saving time), the resulting datetime is invalid.
+ # This is a fatal error. We avoid this edge case by performing date math
+ # on the epoch timestamp, which does not know or care about time zones and
+ # daylight saving time.
+ my $one_day = 24 * 60 * 60;
+ my $one_week = 7 * $one_day;
+ my $one_month = 30 * $one_day;
+
+ query_to_munin( 'pending_user_count',
+ $db->select( 'users', 'count(*) as count', { status => 0 } )
+ ->hash->{count} );
query_to_munin( 'reg_user_count',
$db->select( 'users', 'count(*) as count', { status => 1 } )
->hash->{count} );
@@ -42,19 +59,28 @@ sub run {
);
query_to_munin( 'checked_in',
$db->select( 'in_transit', 'count(*) as count' )->hash->{count} );
- query_to_munin(
- 'checkins_24h',
- $db->query( $checkin_window_query,
- $now->subtract( hours => 24 )->epoch )->hash->{count}
- );
+ query_to_munin( 'checkins_24h',
+ $db->query( $checkin_window_query, $now->epoch - $one_day )
+ ->hash->{count} );
query_to_munin( 'checkins_7d',
- $db->query( $checkin_window_query, $now->subtract( days => 7 )->epoch )
+ $db->query( $checkin_window_query, $now->epoch - $one_week )
+ ->hash->{count} );
+ query_to_munin( 'checkins_30d',
+ $db->query( $checkin_window_query, $now->epoch - $one_month )
+ ->hash->{count} );
+ query_to_munin( 'polylines',
+ $db->select( 'polylines', 'count(*) as count' )->hash->{count} );
+ query_to_munin( 'traewelling_pull',
+ $db->select( 'traewelling', 'count(*) as count', { pull_sync => 1 } )
+ ->hash->{count} );
+ query_to_munin( 'traewelling_push',
+ $db->select( 'traewelling', 'count(*) as count', { push_sync => 1 } )
->hash->{count} );
query_to_munin(
- 'checkins_30d',
+ 'polyline_ratio',
$db->query(
- $checkin_window_query, $now->subtract( days => 30 )->epoch
- )->hash->{count}
+'select (select count(polyline_id) from journeys)::float / (select count(*) from polylines) as ratio'
+ )->hash->{ratio}
);
}