Page 1 of 1
[Resolved] Log volume of traffic tunneled by a user
Posted: Wed Dec 14, 2011 10:59 pm
by TJNII
So more adventures in policy compliance:
Corporate IT requires that, per session, VPN servers log the "volume of session traffic." I don't see any openVPN options to do this directly, so I can think of two options:
1) set verb 6 and log all the packets. This meets the reqs assuming they'll accept a packet count as a metric. It is also very noisy and I'd like something a little cleaner.
2) Use a script to pull the data out of ifconfig tun#. This is great if I'm routing, however I'm bridging for failover and to eliminate the need for NAT. My understanding is that, when bridging, the tap adapter is shared by all the clients. I've checked this experimentally, which means that I can't use this method to get per-session metrics when bridging.
Is there a openVPN option that can track this? Are there other workarounds I haven't thought of? Thanks.
Re: Log volume of traffic tunneled by a user
Posted: Thu Dec 15, 2011 9:04 am
by janjust
do you need to log the amount of data, or the actual data?
to log the amount of data, use the openvpn 'status' file.
to log the actual data, 'verb 6' or a packet sniffer is required.
Re: Log volume of traffic tunneled by a user
Posted: Thu Dec 15, 2011 10:53 am
by maikcat
i have the feeling that you want to implement
some type of volume traffic...
if yes you simply look for amount of data,not data it self.
Michael.
Re: Log volume of traffic tunneled by a user
Posted: Wed Dec 21, 2011 7:55 pm
by TJNII
Status is giving me the info I want, and sending openvpn SIGUSR2 gives it in the manner I want.
Hooking into the --down-pre hook seems to be a graceful solution here, as it should cause the info I want to be written to syslog on connection close. I'm having difficulty with this, though, but I've opened another thread on it.
Re: Log volume of traffic tunneled by a user
Posted: Fri Dec 23, 2011 7:04 pm
by TJNII
My final solution was to call this script on client-disconnect
Code: Select all
#!/bin/bash
# logTraffic.sh: Generate a log entry with IT mandated fields
# 12/23/11 Tom Noonan II <Email Removed>
## Mandatory variables
sessionStart="UNSET"
clientHostAddress="UNSET"
clientUID="UNSET"
sessionDuration="UNSET"
txVolume="UNSET"
rxVolume="UNSET"
## Parse variables
if [ ! -z "$time_ascii" ]; then
sessionStart=$time_ascii
fi
if [ ! -z "$trusted_ip" ]; then
clientHostAddress=$trusted_ip
fi
if [ ! -z "$username" ]; then
clientUID=$username
fi
if [ ! -z "$time_duration" ]; then
sessionDuration=$time_duration
fi
if [ ! -z "$bytes_sent" ]; then
txVolume=$bytes_sent
fi
if [ ! -z "$bytes_received" ]; then
rxVolume=$bytes_received
fi
## Send to syslog
logger -t openvpn -- "Client Disconnect: Username: $clientUID HostIP: $clientHostAddress"
logger -t openvpn -- "Session Duration: $sessionDuration seconds opened at $sessionStart"
logger -t openvpn -- "Session Traffic: TX: $txVolume bytes RX: $rxVolume bytes"
That sends the info to syslog, so I can use syslog servers instead of log files.
Re: [Resolved] Log volume of traffic tunneled by a user
Posted: Sun Dec 25, 2011 10:17 am
by Mimiko
Please write a tutorial about what you accomplished and what did you do from the standard configuration to achieve this.
Re: [Resolved] Log volume of traffic tunneled by a user
Posted: Thu Dec 29, 2011 5:21 am
by dhruvpandit
yeah, a tutorial will be helpful to all

Per user data transfer caps
Posted: Fri Oct 19, 2012 2:32 pm
by DarwinDuck
Hi,
Does anyone one have a solution for capping the data transfer on an openvpn user connection to a set value for that user?
Thanks.
Re: Log volume of traffic tunneled by a user
Posted: Sat Oct 20, 2012 5:03 pm
by DarwinDuck
TJNII wrote:My final solution was to call this script on client-disconnect
Code: Select all
#!/bin/bash
# logTraffic.sh: Generate a log entry with IT mandated fields
# 12/23/11 Tom Noonan II <Email Removed>
## Mandatory variables
sessionStart="UNSET"
clientHostAddress="UNSET"
clientUID="UNSET"
sessionDuration="UNSET"
txVolume="UNSET"
rxVolume="UNSET"
## Parse variables
if [ ! -z "$time_ascii" ]; then
sessionStart=$time_ascii
fi
if [ ! -z "$trusted_ip" ]; then
clientHostAddress=$trusted_ip
fi
if [ ! -z "$username" ]; then
clientUID=$username
fi
if [ ! -z "$time_duration" ]; then
sessionDuration=$time_duration
fi
if [ ! -z "$bytes_sent" ]; then
txVolume=$bytes_sent
fi
if [ ! -z "$bytes_received" ]; then
rxVolume=$bytes_received
fi
## Send to syslog
logger -t openvpn -- "Client Disconnect: Username: $clientUID HostIP: $clientHostAddress"
logger -t openvpn -- "Session Duration: $sessionDuration seconds opened at $sessionStart"
logger -t openvpn -- "Session Traffic: TX: $txVolume bytes RX: $rxVolume bytes"
That sends the info to syslog, so I can use syslog servers instead of log files.
TJNII I would like to do exactly this .. can you elaborate on your solution?
Re: [Resolved] Log volume of traffic tunneled by a user
Posted: Wed Jan 13, 2016 8:54 am
by csibe
I have also written a script which doing the same. When the user disconnects it writes the datas to a txt file.
By the way i made it a little bit better, rewrite it in PHP then now my script doint the sama and writes the data to an SQL database.
If needed i can make tutorial.
Re: [Resolved] Log volume of traffic tunneled by a user
Posted: Wed Jul 31, 2024 9:04 am
by John Smith
Hello
What is the most efficient way to count traffic from Management terminal?
Right now i count data with status command (BytesReceived, BytesSent)