After setting up the OpenVPN server I wanted to measure how much data the clients were using. I didn’t want to limit it but have an idea of how many MB they used.
I searched quite a lot on the Internet but I didn’t find a good solution. I’ll present my solution here.
In the /etc/openvpn/server.conf (or similar file for your server configuration) add the lines:
script-security 2
client-connect /etc/openvpn/scripts/client-connect.sh
client-disconnect /etc/openvpn/scripts/client-disconnect.sh
Then create the files client-connect.sh and specially client-disconnect.sh.
Using this will log the number of bytes used by a connection like:
Apr 14 23:18:31 localhost openvpn: Session $Client TX: 592794812 bytes RX: 42195316 bytes Duration: 11679 seconds HostIP: $IP
Then we might want an easy way to show the number of MB to make it easier to read. For example, using this script in Python:
Apr 14 23:18:31 $Client TX: 565.333187 MB RX: 40.240589 MB 194 min. $IP
So doing this finally I had the information that I wanted.
Leave a Reply