Hello all,
To be honest, I'm lost, I only know the basics.
I would like to show the total bytes transferred per user in the Squid access log.
I have managed to cobble the below to show my total usage.
Do I use a hash and assign an array of byte values to each key/value pair of each user in the hash?
I've looked at lists, linked lists, hashes of hashes, arrays of arrays etc. but it's overwhelming.
Basically, parse the log, take the user and store the value, next user in the log, store the value, match same user, take the bytes field and correlate to the user. Parse the whole log, add all byte values per user to total up and print.
#!/usr/bin/perl
use strict;
use warnings;
my $bytes;
open(FILE, "squid.log") or die $!;
while(<FILE>) {
next unless m/\d+\s\d+\s\d+.\d+.\d+.\d+\s\w+\/\d+\s(\d+)\s\w+\s(.*?
+)\s(?!-)\w+\s\w+\/(?!172.\d+.\d+.\d+)/;
#1257981327.964 212098 172.16.32.142 TCP_MISS/200 3037 CONNECT mail
+.google.com:443 rgabriel DIRECT/172.16.32.14 -
$bytes += $1;
}
close(FILE);
print "$bytes\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.