OpenVPN statistics

Hi,

currently, when an active OpenVPN connection exists, I can look at some statistics like

Are those metrics persistently saved somewhere in the filesystem? Can they be accessed and collected for some reports?

Michael

I am using the available scripts on connect and disconnect to store Informations like ip, time, duration, transfered data.

Take a look at /var/ipfire/ovpn/server.conf

client-connect /var/ipfire/ovpn/scripts/openvpn_up.sh
client-disconnect /var/ipfire/ovpn/scripts/openvpn_down.sh

Sample openvpn_up.sh

#!/bin/bash

NOW="$(date +"%d.%m.%Y %H:%M:%S")"
LOGC=/var/log/OpenVPNConnect.log
RDNS="$(host $untrusted_ip | awk ‘{print $NF}’)"

echo “$NOW OpenVPN connect $common_name from $RDNS with IP $untrusted_ip to IP $ifconfig_pool_remote_ip” >> $LOGC

exit 0

Thanks for your reply.

I’ve found that OpenVPN itself writes some logs into /var/run/ovpnserver.log, that looks like

OpenVPN CLIENT LIST
Updated,Sat May 2 11:31:30 2020
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
Michael,80.187.xxx.xxx:2610,704769,2178219,Sat May 2 11:07:50 2020
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
10.114.101.10,Michael,80.187.xxx.xxx:2610,Sat May 2 11:31:24 2020
GLOBAL STATS
Max bcast/mcast queue length,0
END

The content disappears some seconds after the client disconntects but with the help of your up and down scripts this may be worth to inverstigate a bit further.

Guess when more than one client is connected, some more lines will be present within section OpenVPN CLIENT LIST above.

Now looking for a script to convert those log lines into some key,value pairs…

Edit: a starting point is the CGI file /srv/web/ipfire/cgi-bin/ovpnmain.cgi, however I’m not a Perl guy at all :stuck_out_tongue_winking_eye:

Edit2: for the records, guess, I’ve already found a Python lib which will do the job for me: https://github.com/tonyseek/openvpn-status Let’s see if it’s of any help…

Michael

https://git.ipfire.org/?p=ipfire-2.x.git;a=commit;h=3e10b3de4af03caa2f34f2bfbb50a07f85ec5426 ?

Best,

Erik

Thanks!

This means the WebIF will get some more statistics or a report? I see some comments or coding about a database connection or db related queries, but I’ve not clue about what’s coming next.

Anyway, my intention is to move those data into a database (InfluxDB) and use Grafana for visual representation.

Michael

Your welcome.

Yes, there will be some OpenVPN statistics over the WUI available.

I see.

Best,

Erik

2 Likes