[Resolved] Log volume of traffic tunneled by a user

Need help configuring your VPN? Just post here and you'll get that help.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
TJNII
OpenVpn Newbie
Posts: 10
Joined: Mon Dec 12, 2011 11:32 pm

[Resolved] Log volume of traffic tunneled by a user

Post by TJNII » Wed Dec 14, 2011 10:59 pm

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.
Last edited by TJNII on Fri Dec 23, 2011 7:04 pm, edited 1 time in total.

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Log volume of traffic tunneled by a user

Post by janjust » Thu Dec 15, 2011 9:04 am

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.

User avatar
maikcat
Forum Team
Posts: 4200
Joined: Wed Jan 12, 2011 9:23 am
Location: Athens,Greece
Contact:

Re: Log volume of traffic tunneled by a user

Post by maikcat » Thu Dec 15, 2011 10:53 am

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.
Amiga 500 , Zx +2 owner
Long live Dino Dini (Kick off 2 Creator)

Inflammable means flammable? (Dr Nick Riviera,Simsons Season13)

"objects in mirror are losing"

TJNII
OpenVpn Newbie
Posts: 10
Joined: Mon Dec 12, 2011 11:32 pm

Re: Log volume of traffic tunneled by a user

Post by TJNII » Wed Dec 21, 2011 7:55 pm

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.

TJNII
OpenVpn Newbie
Posts: 10
Joined: Mon Dec 12, 2011 11:32 pm

Re: Log volume of traffic tunneled by a user

Post by TJNII » Fri Dec 23, 2011 7:04 pm

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.

User avatar
Mimiko
Forum Team
Posts: 1564
Joined: Wed Sep 22, 2010 3:18 am

Re: [Resolved] Log volume of traffic tunneled by a user

Post by Mimiko » Sun Dec 25, 2011 10:17 am

Please write a tutorial about what you accomplished and what did you do from the standard configuration to achieve this.

dhruvpandit
OpenVPN Power User
Posts: 53
Joined: Tue Apr 19, 2011 11:18 am

Re: [Resolved] Log volume of traffic tunneled by a user

Post by dhruvpandit » Thu Dec 29, 2011 5:21 am

yeah, a tutorial will be helpful to all :)

DarwinDuck
OpenVpn Newbie
Posts: 16
Joined: Wed Feb 08, 2012 11:52 pm

Per user data transfer caps

Post by DarwinDuck » Fri Oct 19, 2012 2:32 pm

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.

DarwinDuck
OpenVpn Newbie
Posts: 16
Joined: Wed Feb 08, 2012 11:52 pm

Re: Log volume of traffic tunneled by a user

Post by DarwinDuck » Sat Oct 20, 2012 5:03 pm

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?

csibe
OpenVpn Newbie
Posts: 12
Joined: Tue Aug 26, 2014 5:20 pm

Re: [Resolved] Log volume of traffic tunneled by a user

Post by csibe » Wed Jan 13, 2016 8:54 am

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.

John Smith
OpenVpn Newbie
Posts: 1
Joined: Wed Jul 31, 2024 9:01 am

Re: [Resolved] Log volume of traffic tunneled by a user

Post by John Smith » Wed Jul 31, 2024 9:04 am

Hello

What is the most efficient way to count traffic from Management terminal?

Right now i count data with status command (BytesReceived, BytesSent)

Post Reply