6 use POSIX qw(strftime);
7 use Data::Dump qw(dump);
10 my $debug = $ENV{DEBUG} || 0;
15 return strftime("%Y-%m-%d %H:%M:%S", localtime($_[0]));
19 open(my $log_fh, '<', "/var/log/apache2/other_vhosts_access.log");
21 my ( $t, $duration ) = @_;
22 my $tell = tell($log_fh);
23 print "XXX log_time $t ", t_iso($t) , " $tell\n" if $debug;
27 if ( m/ \[(\d+[^\]]+)\] \S+ (\S+)/ ) {
28 my $t_l = str2time($1);
31 print "XXX log line ",t_iso($t_l)," $dt tell ",tell($log_fh),$/ if abs($dt) < 5 && $debug;
32 if ( abs( $dt ) <= $duration && $url =~ m/cgi/ ) {
34 $tell = tell($log_fh) if $found == 1;
36 print "\nFOUND $tell $dt ",t_iso( $t_l ), " ", t_iso($t), " ", $_;
38 printf "FOUND %4.1f %s", $dt, $_;
42 ( $found && $t_l - $t > $duration * 3 ) ||
43 ( ! $found && $t_l - $t > 90 ) # apache log entries come after more than 60s sometime
44 ) { # overshoot time since logs are not always in order
45 print "STOP ", t_iso($t_l), " tell $tell\n" if $debug;
46 seek($log_fh, $tell, 0);
52 print "SEEK $tell\n" if $debug;
53 seek($log_fh, $tell, 0);
62 open(my $slow_fh, '<', '/var/log/mysql/mysql-slow.log');
65 if ( m/Time:\s+(\S+)\s+(\S+)/ ) {
66 $t = str2time("20$1 $2");
67 } elsif ( m/Query_time: (\S+)/ ) {
69 my $t_start = $t - $d;
70 print "XXX ",t_iso($t), " -> ", t_iso($t_start), $/ if $debug;
72 log_time $t_start, $d;
73 } elsif ( m/SET timestamp=(\d+);/ ) {
79 open(my $sql_fh, '>', t_iso($t) . "-$in_sql-$sql_count.sql");