]> git.ipfire.org Git - thirdparty/squid.git/blob - scripts/PerUser.pl
Source Format Enforcement (#763)
[thirdparty/squid.git] / scripts / PerUser.pl
1 #!/usr/bin/perl -w
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 # This is a simple script that will summarise per-user traffic
11 # statistics.
12 #
13 # Adrian Chadd <adrian@squid-cache.org>
14 # CVS-Id: PerUser.pl,v 1.2 2007/01/24 08:03:52 adrian Exp
15
16 use strict;
17 use Squid::ParseLog;
18
19 my %u;
20 my $wh;
21
22 $wh = "username";
23 if (scalar @ARGV >= 1) {
24 $wh = $ARGV[0];
25 shift @ARGV;
26 }
27
28 while (<>) {
29 chomp;
30 my $l = Squid::ParseLog::parse($_);
31 if (! defined $u{$l->{$wh}}) {
32 $u{$l->{$wh}}->{"traffic"} = 0;
33 }
34 $u{$l->{$wh}}->{"traffic"} += $l->{"size"};
35 }
36
37 foreach (keys %u) {
38 printf "%s\t\t%lu\n", $_, $u{$_}->{"traffic"};
39 }