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+[^\]]+)\] / ) {
28 my $t_l = str2time($1);
30 print "XXX log line ",t_iso($t_l)," $dt tell ",tell($log_fh),$/ if abs($dt) < 5 && $debug;
31 # if ( $dt > -2 && $dt < 3 ) {
32 if ( abs( $dt ) <= $duration ) {
33 # if ( $t_l == $t or $t_l - $t < 2 ) { #abs( $t_l - $t ) < 2 ) {
35 $tell = tell($log_fh) if $found == 1;
37 print "\nFOUND $tell $dt ",t_iso( $t_l ), " ", t_iso($t), " ", $_;
39 printf "FOUND %.1f %s", $dt, $_;
43 ( $found && $t_l - $t > $duration * 3 ) ||
44 ( ! $found && $t_l - $t > 40 ) # apache log entries come after 30s sometime
45 ) { # overshoot time since logs are not always in order
46 print "STOP ", t_iso($t_l), " tell $tell\n" if $debug;
47 seek($log_fh, $tell, 0);
53 print "SEEK $tell\n" if $debug;
54 seek($log_fh, $tell, 0);
59 open(my $slow_fh, '<', '/var/log/mysql/mysql-slow.log');
62 if ( m/Time:\s+(\S+)\s+(\S+)/ ) {
63 $t = str2time("20$1 $2");
64 } elsif ( m/Query_time: (\S+)/ ) {
66 my $t_start = $t - $d;
67 print "XXX ",t_iso($t), " -> ", t_iso($t_start), $/ if $debug;
69 log_time $t_start, $d;
76 stdbuf -o L cat /var/log/mysql/mysql-slow.log \
77 | stdbuf -e L tee /dev/stderr \
78 | stdbuf -o L grep Time: \
79 | stdbuf -o L awk '{ print "grep --line-buffered " $4 " /var/log/apache2/other_vhosts_access.log-20"$3 ; fflush(stdout); }' | sh
83 zgrep Query_time /var/log/mysql/mysql-slow.log*
87 grep -E '(Query_time|Time)' /var/log/mysql/mysql-slow.log