]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/access-log-matrix.pl
Source Format Enforcement (#763)
[thirdparty/squid.git] / scripts / access-log-matrix.pl
1 #!/usr/local/bin/perl
2 #
3 ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 ##
5 ## Squid software is distributed under GPLv2+ license and includes
6 ## contributions from numerous individuals and organizations.
7 ## Please see the COPYING and CONTRIBUTORS files for details.
8 ##
9 #
10 # access-log-matrix.pl
11 #
12 # Duane Wessels, Dec 1995
13 #
14 # Stdin is a Harvest access log (in the old, non-common logfile format!).
15 # The output is a matrix of hostnames and log entry types, plus totals.
16
17 while (<>) {
18 chop;
19 @F = split;
20 $when = $F[0];
21 $first = $when unless ($first);
22 $last = $when;
23
24 $what = pop @F;
25 $size = pop @F;
26 $host = pop @F;
27
28 $HOSTS{$host}++;
29 $HOSTS{'TOTAL'}++;
30
31 if ($what eq 'TCP_DONE') {
32 $TCP_DONE{$host}++;
33 $TCP_DONE{'TOTAL'}++;
34 } elsif ($what eq 'TCP_HIT') {
35 $TCP_HIT{$host}++;
36 $TCP_HIT{'TOTAL'}++;
37 } elsif ($what eq 'TCP_MISS') {
38 $TCP_MISS{$host}++;
39 $TCP_MISS{'TOTAL'}++;
40 } elsif ($what eq 'TCP_MISS_TTL') {
41 $TCP_MISS_TTL{$host}++;
42 $TCP_MISS_TTL{'TOTAL'}++;
43 } elsif ($what eq 'UDP_HIT') {
44 $UDP_HIT{$host}++;
45 $UDP_HIT{'TOTAL'}++;
46 } elsif ($what eq 'UDP_MISS') {
47 $UDP_MISS{$host}++;
48 $UDP_MISS{'TOTAL'}++;
49 } else {
50 $OTHER{$host}++;
51 $OTHER{'TOTAL'}++;
52 }
53 }
54
55 print ' HOSTNAME: '. `hostname`;
56 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($first);
57 printf "FIRST LOG ENTRY: %04d/%02d/%02d %.2d:%.2d:%.2d\n", $year+1900,$mon+1,$mday, $hour,$min,$sec;
58 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($last);
59 printf " LAST LOG ENTRY: %04d/%02d/%02d %.2d:%.2d:%.2d\n", $year+1900,$mon+1,$mday, $hour,$min,$sec;
60 print "\n";
61
62 printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n",
63 '',
64 'TCP', 'TCP', 'TCP', 'TCP',
65 'UDP', 'UDP', '',
66 '');
67 printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n",
68 'HOST',
69 'HIT', 'MISS', 'TTL', 'DONE',
70 'HIT', 'MISS', 'OTHER',
71 'TOTAL');
72
73 printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n",
74 '-'x25,
75 '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5);
76
77 foreach $h (sort totalcmp keys %HOSTS) {
78 next if ($h eq 'TOTAL');
79 ($a1,$a2,$a3,$a4) = split('\.', $h);
80 ($fqdn, @F) = gethostbyaddr(pack('C4',$a1,$a2,$a3,$a4),2);
81 $fqdn = $h unless ($fqdn ne '');
82
83 printf "%25.25s %5d %5d %5d %5d %5d %5d %5d %5d\n",
84 $fqdn,
85 $TCP_HIT{$h},
86 $TCP_MISS{$h},
87 $TCP_MISS_TTL{$h},
88 $TCP_DONE{$h},
89 $UDP_HIT{$h},
90 $UDP_MISS{$h},
91 $OTHER{$h},
92 $HOSTS{$h};
93
94 }
95
96
97 printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n",
98 '-'x25,
99 '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5);
100 printf "%25.25s %5d %5d %5d %5d %5d %5d %5d %5d\n",
101 'TOTAL',
102 $TCP_HIT{'TOTAL'},
103 $TCP_MISS{'TOTAL'},
104 $TCP_MISS_TTL{'TOTAL'},
105 $TCP_DONE{'TOTAL'},
106 $UDP_HIT{'TOTAL'},
107 $UDP_MISS{'TOTAL'},
108 $OTHER{'TOTAL'},
109 $HOSTS{'TOTAL'};
110
111 exit 0;
112
113 sub hostcmp {
114 $a cmp $b
115 }
116
117 sub totalcmp {
118 $HOSTS{$b} <=> $HOSTS{$a}
119 }