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