std/c/: Delete the old Perl tests in src/t/, 0:84
[sunny256-utils.git] / access_log-drops
blob4ddfc50c08432ce8d0f6302598ec92c6ac3fd4d1
1 #!/usr/bin/env perl
3 #=======================================================================
4 # access_log-drops
5 # File ID: 94b18e7a-5d36-11df-9276-90e6ba3022ac
6 # Finner drops (ikke sukkertøy, men pauser) i Apache-logger.
8 # Character set: UTF-8
9 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License, see end of file for legal stuff.
11 #=======================================================================
13 use strict;
14 use warnings;
15 use Time::Local;
17 $| = 1;
19 use Getopt::Std;
20 our ($opt_h, $opt_l) =
21 ( 0, 1);
22 getopts('hl:') || die("Option error. Use -h for help.\n");
24 my $VERSION = "0.0";
26 our $progname = $0;
27 $progname =~ s#^.*/(.*?)$#$1#;
29 $opt_h && usage(0);
31 # 194.248.216.3 - - [13/Aug/2001:16:04:37 +0200] "GET
33 my %mnd_hash = (
34 'Jan'=>0, 'Feb'=>1, 'Mar'=>2, 'Apr'=>3, 'May'=>4, 'Jun'=>5,
35 'Jul'=>6, 'Aug'=>7, 'Sep'=>8, 'Oct'=>9, 'Nov'=>10, 'Dec'=>11
38 my $last_sec = 0;
40 while (<>) {
41 if (
42 # access_log-regexp {{{
44 \S+ # IP
45 \s+
46 \S+
47 \s+
48 \S+
49 \s+
51 (\d+) # Dato
53 (\S+) # Mnd
55 (\d{4}) # År
56 :(\d\d):(\d\d):(\d\d) # Klokka
57 \s+
58 ([+\-]\d\d)(\d\d)
60 # }}}
61 ) {
62 my ($Day, $Mon, $Year, $Hour, $Min, $Sec, $zone_hour, $zone_min) =
63 ( $1, $2, $3, $4, $5, $6, $7, $8);
64 my $num_mon = $mnd_hash{$Mon};
65 my $Secs = timegm($Sec, $Min, $Hour, $Day, $num_mon, $Year);
66 $Secs -= ($zone_hour*3600); # Vi driter i minuttene for å få opp farta.
67 my $Pause = $Secs - $last_sec;
68 if ($last_sec && ($Pause >= $opt_l)) {
69 $num_mon++; # Å inn i svarteste hælvete hvor jeg hater det inkonsekvente pisset der!!!!!!!!!!!!!!!!
70 printf(
71 "%04u-%02u-%02uT%02u:%02u:%02uZ %4u %s\n",
72 $Year, $num_mon, $Day, $Hour, $Min, $Sec,
73 $Pause, sec_to_hms($Pause)
76 $last_sec = $Secs;
77 } else {
78 print(STDERR "Ukjent linje $.\n");
82 sub sec_to_hms {
83 # {{{
84 my $secs = shift;
85 my ($Day, $Hour, $Min, $Sec) = (0, 0, 0, 0);
87 $Day = int($secs/86400);
88 $secs -= $Day*86400;
90 $Hour = int($secs/3600);
91 $secs -= $Hour * 3600;
93 $Min = int($secs/60);
94 $secs -= $Min * 60;
96 $Sec = $secs;
98 return(($Day ? "$Day:" : "") . sprintf("%02u:%02u:%02u", $Hour, $Min, $Sec));
99 # }}}
100 } # Tidsperiode()
102 sub usage {
103 # Send the help message to stdout {{{
104 my $Retval = shift;
105 print(<<END);
106 $progname v$VERSION
108 Usage: $progname [options] [file [...]]
110 Scans Apache access logs and prints out time periods with no connections.
112 Options:
114 -h Print this help.
115 -l x Show only pauses longer than x seconds.
118 exit($Retval);
119 # }}}
122 __END__
124 # Plain Old Documentation (POD) {{{
126 =pod
128 =head1 NAME
130 access_log-drops — find pauses in Apache logs
132 =head1 SYNOPSIS
134 access_log-drops [options] [file [...]]
136 =head1 DESCRIPTION
140 =head1 OPTIONS
142 =over 4
144 =item B<-h>
146 Print a brief help summary.
148 =item B<-l> x
150 Only list pauses longer than I<x> seconds.
152 =back
154 =head1 BUGS
158 =head1 AUTHOR
160 Made by Øyvind A. Holm S<E<lt>sunny _AT_ sunbase.orgE<gt>>.
162 =head1 COPYRIGHT
164 Copyleft © Øyvind A. Holm &lt;sunny@sunbase.org&gt;
165 This is free software; see the file F<COPYING> for legalese stuff.
167 =head1 LICENCE
169 This program is free software; you can redistribute it and/or modify it
170 under the terms of the GNU General Public License as published by the
171 Free Software Foundation; either version 2 of the License, or (at your
172 option) any later version.
174 This program is distributed in the hope that it will be useful, but
175 WITHOUT ANY WARRANTY; without even the implied warranty of
176 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
177 See the GNU General Public License for more details.
179 You should have received a copy of the GNU General Public License along
180 with this program; if not, write to the Free Software Foundation, Inc.,
181 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
183 =head1 SEE ALSO
185 =cut
187 # }}}
189 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :