]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Adrian Chadd <adrian@squid-cache.org>
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 12 Jul 2009 03:32:39 +0000 (15:32 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 12 Jul 2009 03:32:39 +0000 (15:32 +1200)
Add a simple script to summarise traffic use per user.

And, summarise the user list accessing the proxy.

Allows the user to override the aggregation term.
By default its "username" but there are other options (eg try
"clientip").

scripts/PerUser.pl [new file with mode: 0644]

diff --git a/scripts/PerUser.pl b/scripts/PerUser.pl
new file mode 100644 (file)
index 0000000..26d70a8
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+
+
+use strict;
+
+# This is a simple script that will summarise per-user traffic
+# statistics.
+#
+# Adrian Chadd <adrian@squid-cache.org>
+# $Id: PerUser.pl,v 1.2 2007/01/24 08:03:52 adrian Exp $
+
+use Squid::ParseLog;
+
+my %u;
+my $wh;
+
+$wh = "username";
+if (scalar @ARGV >= 1) {
+       $wh = $ARGV[0];
+       shift @ARGV;
+}
+
+while (<>) {
+       chomp;
+       my $l = Squid::ParseLog::parse($_);
+       if (! defined $u{$l->{$wh}}) {
+               $u{$l->{$wh}}->{"traffic"} = 0;
+       }
+       $u{$l->{$wh}}->{"traffic"} += $l->{"size"};
+}
+
+foreach (keys %u) {
+       printf "%s\t\t%lu\n", $_, $u{$_}->{"traffic"};
+}