Graph amount of OpenVPN users to Munin

Rather simple script. Using log file instead of management interface.

vpnusers-day

Part has to run as Root (due to Munin most likely not having access to read the log files. Working with the management interface could solve this.

Create /usr/local/bin/getVpnUsers.sh:

#!/bin/bash
echo "VPN.value `cat /var/log/openvpn-status.log | sed -e '1,/Common Name/d' | 
sed -e '/ROUTING TABLE/,$d' | wc -l`" > /tmp/.vpn_munin.txt

You can change the name of VPN.value to the VPN name and/or add multiple lines (each with a different NAME.value if you’re running more than one VPN user. Be sure to cat the right log file).

And:

chmod +x /usr/local/bin/getVpnUsers.sh

Add this to root cron:

*/5 * * * * /usr/local/bin/getVpnUsers.sh >/dev/null 2>&1

Now create /etc/munin/plugins/vpnusers:

#!/bin/sh

case $1 in
 config)
 cat <<'EOM'
graph_category network
graph_title oVPN users
graph_vlabel users
VPN.label My oVPN
# add more labels like this:
#isazi.label Isazi VPN
EOM
 exit 0;;
esac

cat /tmp/.vpn_munin.txt

And:

chmod +x /etc/munin/plugins/vpnusers

You’ll need the correct NAME.label in the plugin depending on the name you choose in part one.

And restart munin-node:

/etc/init.d/munin-node restart

That’s it.

Check your Munin under “network”. It might take ~15+ minutes before the graph is generated.

vpnusers-day-1

Leave a Reply...