[OpenVPN home] [Date Prev] [Date Index] [Date Next]
[OpenVPN mailing lists] [Thread Prev] [Thread Index] [Thread Next]
Google
 
Web openvpn.net

Re: [Openvpn-users] Automatically parse and add-up byte-count fromclient-disconnect log - Paying Job!


  • Subject: Re: [Openvpn-users] Automatically parse and add-up byte-count fromclient-disconnect log - Paying Job!
  • From: "Dave" <dev@xxxxxxxxxxxxxx>
  • Date: Sat, 25 Aug 2007 13:40:46 -0500
  • Importance: Normal

Title: Message
...
Over the last two months I have acquired a log file that contains a line for each client-connect and each client-disconnect. The file was created with these two scripts:
...
Here is an example of the file created:

Jul 25 19:01:52 texas01 texas01.example.com openvpn client-connect: admin01
Jul 25 19:02:05 texas01 texas01.example.com openvpn client-disconnect: admin01 7836/7490
...
I would like a way to add-up the byte-count for each user, and if possible the bytes sent and the bytes received (the numbers are separated by a "/" in the log) for each user. I have Windows, Linux, and Mac, so a solution for any platform is acceptable. If there is already something I can use, let me know. Otherwise, I am willing to pay for a simple script to do this for me.
...
 
 
I'm not a Perl programmer, but your scripts intrigued me and caused me to write the following which I think will work with minor modification:
 
--BEGIN SCRIPT openvpn-byte-tally
 
#!/mnt/external/usr/bin/microperl -w
 
%bytes_sent = ();
%bytes_recvd = ();
 
$LOGFILE = "/tmp/openvpn-connect.log";
open(LOGFILE) or die("Could not open log file.");
foreach $line (<LOGFILE>) {
        chomp ( $line );        #remove trailing newline
        # find log line; extract host name, common name, bytes sent and rcvd
        if ( $line =~ /(\w+)\sopenvpn\sclient-disconnect:\s(.*)\s(\d+)\/(\d+)/ ) {
                $bytes_sent{$2} += $3;
                $bytes_recvd{$2} += $4;
        }
}
while ( ($cn,$sent) = each ( %bytes_sent ) ){
        $recvd = $bytes_recvd{$cn};
        print "for client: $cn sent: $sent rec: $recvd\n";
}
close(LOGFILE);
--END SCRIPT openvpn-byte-tally
 
You would need to change the executable to what is your perl interpreter, and also the $LOGFILE to what is your log file.
 
Hopefully this will be of use.
 
-Dave