]>
Commit | Line | Data |
---|---|---|
090089c4 | 1 | #!/usr/local/bin/perl |
a151895d | 2 | # |
f70aedc4 | 3 | ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
a151895d AJ |
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 | # | |
090089c4 | 10 | # access-log-matrix.pl |
47f28373 | 11 | # |
090089c4 | 12 | # Duane Wessels, Dec 1995 |
47f28373 | 13 | # |
090089c4 | 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 (<>) { | |
47f28373 FC |
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'}++; | |
090089c4 | 30 | |
47f28373 FC |
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 | } | |
090089c4 | 53 | } |
54 | ||
55 | print ' HOSTNAME: '. `hostname`; | |
56 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($first); | |
9bc73deb | 57 | printf "FIRST LOG ENTRY: %04d/%02d/%02d %.2d:%.2d:%.2d\n", $year+1900,$mon+1,$mday, $hour,$min,$sec; |
090089c4 | 58 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime($last); |
9bc73deb | 59 | printf " LAST LOG ENTRY: %04d/%02d/%02d %.2d:%.2d:%.2d\n", $year+1900,$mon+1,$mday, $hour,$min,$sec; |
090089c4 | 60 | print "\n"; |
61 | ||
62 | printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n", | |
47f28373 FC |
63 | '', |
64 | 'TCP', 'TCP', 'TCP', 'TCP', | |
65 | 'UDP', 'UDP', '', | |
66 | ''); | |
090089c4 | 67 | printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n", |
47f28373 FC |
68 | 'HOST', |
69 | 'HIT', 'MISS', 'TTL', 'DONE', | |
70 | 'HIT', 'MISS', 'OTHER', | |
71 | 'TOTAL'); | |
090089c4 | 72 | |
73 | printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n", | |
47f28373 FC |
74 | '-'x25, |
75 | '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5); | |
090089c4 | 76 | |
77 | foreach $h (sort totalcmp keys %HOSTS) { | |
47f28373 FC |
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 ''); | |
090089c4 | 82 | |
47f28373 FC |
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}; | |
090089c4 | 93 | |
94 | } | |
95 | ||
96 | ||
97 | printf ("%25.25s %5s %5s %5s %5s %5s %5s %5s %5s\n", | |
47f28373 FC |
98 | '-'x25, |
99 | '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5, '-'x5); | |
090089c4 | 100 | printf "%25.25s %5d %5d %5d %5d %5d %5d %5d %5d\n", |
47f28373 FC |
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'}; | |
090089c4 | 110 | |
111 | exit 0; | |
112 | ||
113 | sub hostcmp { | |
47f28373 | 114 | $a cmp $b |
090089c4 | 115 | } |
116 | ||
117 | sub totalcmp { | |
47f28373 | 118 | $HOSTS{$b} <=> $HOSTS{$a} |
090089c4 | 119 | } |