From 2b8fdda37f6a76c9dc252e2d26a7fa75c9170526 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 13 Sep 2015 20:42:07 +0200 Subject: add optional stats support --- index.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'index.pl') diff --git a/index.pl b/index.pl index 0e4ce3c..82cf7e7 100644 --- a/index.pl +++ b/index.pl @@ -1,6 +1,7 @@ #!/usr/bin/env perl use Mojolicious::Lite; use Cache::File; +use File::Slurp qw(read_file write_file); use List::MoreUtils qw(); use Travel::Status::DE::DeutscheBahn; use Travel::Status::DE::IRIS; @@ -14,6 +15,14 @@ our $VERSION = qx{git describe --dirty} || '0.05'; my $refresh_interval = 180; +sub log_api_access { + my $counter = 1; + if ( -r $ENV{DBFAKEDISPLAY_STATS} ) { + $counter = read_file( $ENV{DBFAKEDISPLAY_STATS} ) + 1; + } + write_file( $ENV{DBFAKEDISPLAY_STATS}, $counter ); +} + sub get_results_for { my ( $backend, $station, %opt ) = @_; @@ -33,6 +42,9 @@ sub get_results_for { my $data = $cache->thaw($cache_str); if ( not $data ) { + if ( $ENV{DBFAKEDISPLAY_STATS} ) { + log_api_access(); + } if ( $backend eq 'iris' ) { # requests with DS100 codes should be preferred (they avoid -- cgit v1.2.3