What's new

Displaying uptime OpenVPN client

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Intrepid2007

Regular Contributor
Unfortunately, the uptime is not available at the page where OpenVPN client statistics are shown.

Is there another way to find this info? Maybe via telnet? I have a RT-AX88U

Thanks
 
Unfortunately, the uptime is not available at the page where OpenVPN client statistics are shown.

Is there another way to find this info? Maybe via telnet? I have a RT-AX88U
The VPN Client '/etc/openvpn/clientX/status' file does not track/contain the UP time

However, a crude method would be to manually record the VPN Client initialised time (to a file) using the openvpn-event 'vpnclientX-up' trigger script

e.g. VPN Client 4
Code:
VPN_ID=4;echo "$(date "+%F %T")" > /tmp/vpnclient$VPN_ID.log
then when appropriate you can simply compare the timestamp in '/tmp/vpnclient$VPN_ID.log' to the current time to calculate the elapsed duration.

e.g. Determine the TOTAL (PID UP time) in the openvpn-event vpnclientX-down trigger script.

Alternatively you could use a SyslogEventMonitor script to track the VPN Client events and calculate the actual duration in more detail.
 
Last edited:
The VPN Client '/etc/openvpn/clientX/status' file does not track/contain the UP time

However, a crude method would be to manually record the VPN Client initialised time (to a file) using the openvpn-event 'vpnclientX-up' trigger script

e.g. VPN Client 4
Code:
VPN_ID=4;echo "$(date "+%F %T")" > /tmp/vpnclient$VPN_ID.log
then when appropriate you can simply compare the timestamp in '/tmp/vpnclient$VPN_ID.log' to the current time to calculate the elapsed duration.

e.g. Determine the TOTAL (PID UP time) in the openvpn-event vpnclientX-down trigger script.

Alternatively you could use a SyslogEventMonitor script to track the VPN Client events and calculate the actual duration in more detail.

Thank you for your reply...
Unfortunately I am not familiar with scripting and how to implement it in Asus routers..

Indeed, the SyslogEventMonitor has this information. I could configure the router to send it's log data to a utility that analyses the log data. I am interested how stable is the vpn connection and the uptime is an indication. Writing such a utility is not too much work.
 
Last edited:
Sorry for bringing up an old thread.
I too is curious to know what is my vpn client uptime. Sometimes I find the connection stale and I have to manually reset the vpn connection to get it up again.
Thanks @Martineau, I have added your suggestion to create a time logging. Anyone has develop some script for this?
 
Sorry for bringing up an old thread.
I too is curious to know what is my vpn client uptime. Sometimes I find the connection stale and I have to manually reset the vpn connection to get it up again.
Thanks @Martineau, I have added your suggestion to create a time logging. Anyone has develop some script for this?
A script to display the VPN connection session duration, or to detect stale/degraded throughput VPN Client connections?

i.e. To simply display the tracking time, I use the following
Code:
# Extract the timestamp from the VPN tracker file

VPN_ID=$1            # Select the appropriate VPN Client instance either dynamically (arg) or static (e.g. 'VPN_ID=5')

if [ -f /tmp/vpnclient${VPN_ID}.log ];then
    SESSION_TIMESTAMP=$(date -r /tmp/vpnclient${VPN_ID}.log +%s)
    CURRENT_TIMESTAMP=$(date +%s)
    echo $(($(date +%s)-$(date -r /tmp/vpnclient${VPN_ID}.log +%s))) | awk '{printf("%d days %02d hours %02d minutes %02d seconds\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
    #echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration" $(Convert_SECS_to_HHMMSS "$((CURRENT_TIMESTAMP-SESSION_TIMESTAMP))" "daystext")  >&2
else
    echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration not tracked...missing '/tmp/vpnclient${VPN_ID}.log'. Check 'openvpn-event:vpnclient${VPN_ID}-up'" >&2
fi
e.g.
Code:
./VPN_Client_Switch.sh status

(VPN_Client_Switch.sh): 14642 v1.11 Request..... [status]


    VPN Client Status:

        Client 1 Connected session duration 3 days 00 hours 49 minutes 45 seconds
                 Connection 553:udp to 100.120.249.243 (HMA New York)           VPN STUN tunnel end-point I/P: 212.102.33.48
        Checking response (max 5secs) from 'http://ipecho.net/plain' to verify  VPN tunnel end-point I/P: 212.102.33.48
<snip>
 
Last edited:
A script to display the VPN connection session duration, or to detect stale/degraded throughput VPN Client connections?

i.e. To simply display the tracking time, I use the following
Code:
# Extract the timestamp from the VPN tracker file

VPN_ID=$1            # Select the appropriate VPN Client instance either dynamically (arg) or static (e.g. 'VPN_ID=5')

if [ -f /tmp/vpnclient${VPN_ID}.log ];then
    local SESSION_TIMESTAMP=$(date -r /tmp/vpnclient${VPN_ID}.log +%s)
    local CURRENT_TIMESTAMP=$(date +%s)
    #echo $(($(date +%s)-$(date -r /tmp/vpnclient${VPN_ID}.log +%s))) | awk '{printf("%d days %02d hours %02d minutes %02d seconds\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
    echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration" $(Convert_SECS_to_HHMMSS "$((CURRENT_TIMESTAMP-SESSION_TIMESTAMP))" "daystext")  >&2
else
    echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration not tracked...missing '/tmp/vpnclient${VPN_ID}.log'. Check 'openvpn-event:vpnclient${VPN_ID}-up'" >&2
fi
e.g.
Code:
./VPN_Client_Switch.sh status

(VPN_Client_Switch.sh): 14642 v1.11 Request..... [status]


    VPN Client Status:

        Client 1 Connected session duration 3 days 00 hours 49 minutes 45 seconds
                 Connection 553:udp to 100.120.249.243 (HMA New York)           VPN STUN tunnel end-point I/P: 212.102.33.48
        Checking response (max 5secs) from 'http://ipecho.net/plain' to verify  VPN tunnel end-point I/P: 212.102.33.48
<snip>
Thanks @Martineau. Perhaps a bit of both is better :) .
I have two VPN client running. Do I have to specify which VPN client ID or just use it as it is? I try to use it as is, and I am getting some error message. Can you help me see what could be the problem?
Code:
admin@RT-AC86U-DBA8:/jffs/scripts# ./VPN_Client_Switch.sh status
./VPN_Client_Switch.sh: local: line 12: not in a function
./VPN_Client_Switch.sh: local: line 12: not in a function
./VPN_Client_Switch.sh: line 12: Convert_SECS_to_HHMMSS: not found

                Client status Connected session duration
admin@RT-AC86U-DBA8:/jffs/scripts#
 
Thanks @Martineau. Perhaps a bit of both is better :) .
I have two VPN client running. Do I have to specify which VPN client ID or just use it as it is? I try to use it as is, and I am getting some error message. Can you help me see what could be the problem?
Code:
admin@RT-AC86U-DBA8:/jffs/scripts# ./VPN_Client_Switch.sh status
./VPN_Client_Switch.sh: local: line 12: not in a function
./VPN_Client_Switch.sh: local: line 12: not in a function
./VPN_Client_Switch.sh: line 12: Convert_SECS_to_HHMMSS: not found

                Client status Connected session duration
admin@RT-AC86U-DBA8:/jffs/scripts#
The code snippet was an example of how to use the VPN Client tracker file.

You said you had modified a script to initialise the tracker so assumed you could understand the snippet.

I have now simply commented out the lines causing you the errors and uncommented the line that should work and added the loop for your two VPN Clients
Code:
for VPN_ID in 1 2
    do
        if [ -f /tmp/vpnclient${VPN_ID}.log ];then
            #SESSION_TIMESTAMP=$(date -r /tmp/vpnclient${VPN_ID}.log +%s)
            #CURRENT_TIMESTAMP=$(date +%s)
            #echo $(($(date +%s)-$(date -r /tmp/vpnclient${VPN_ID}.log +%s))) | awk '{printf("%d days %02d hours %02d minutes %02d seconds\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
            echo $(($(date +%s)-$(date -r /tmp/vpnclient${VPN_ID}.log +%s))) $VPN_ID | awk '{printf("VPN Client %d uptime %d days %02d hours %02d minutes %02d seconds\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
            #echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration" $(Convert_SECS_to_HHMMSS "$((CURRENT_TIMESTAMP-SESSION_TIMESTAMP))" "daystext")  >&2
        else
            echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration not tracked...missing '/tmp/vpnclient${VPN_ID}.log'. Check 'openvpn-event:vpnclient${VPN_ID}-up'" >&2
        fi
    done

EDIT: Include VPN Client instance in output
e.g.
Code:
VPN Client 1 uptime 0 days 00 hours 09 minutes 20 seconds
VPN Client 2 uptime 0 days 00 hours 08 minutes 00 seconds
 
Last edited:
The code snippet was an example of how to use the VPN Client tracker file.

You said you had modified a script to initialise the tracker so assumed you could understand the snippet.

I have now simply commented out the lines causing you the errors and uncommented the line that should work and added the loop for your two VPN Clients
Code:
for VPN_ID in 1 2
    do
        if [ -f /tmp/vpnclient${VPN_ID}.log ];then
            #SESSION_TIMESTAMP=$(date -r /tmp/vpnclient${VPN_ID}.log +%s)
            #CURRENT_TIMESTAMP=$(date +%s)
            echo $(($(date +%s)-$(date -r /tmp/vpnclient${VPN_ID}.log +%s))) | awk '{printf("%d days %02d hours %02d minutes %02d seconds\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
            #echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration" $(Convert_SECS_to_HHMMSS "$((CURRENT_TIMESTAMP-SESSION_TIMESTAMP))" "daystext")  >&2
        else
            echo -e $cBGRE"\n\t\tClient ${VPN_ID} Connected session duration not tracked...missing '/tmp/vpnclient${VPN_ID}.log'. Check 'openvpn-event:vpnclient${VPN_ID}-up'" >&2
        fi
    done
Thanks again @Martineau. Now I get to see the output.

Edit: Really appreciate your help. The enhanced version to include VPN instance is even better. Now I have it on a cronjob for logging.

Update: Logging is good.
Code:
May 23 14:40:00 RT-AC86U-xxxx VPN Client 1 is connected for 8 days, 13 hours 55 minutes 20 seconds
May 23 14:40:00 RT-AC86U-xxxx VPN Client 3 is connected for 1 days, 14 hours 00 minutes 27 seconds
May 23 14:50:00 RT-AC86U-xxxx VPN Client 1 is connected for 8 days, 14 hours 05 minutes 20 seconds
May 23 14:50:00 RT-AC86U-xxxx VPN Client 3 is connected for 1 days, 14 hours 10 minutes 27 seconds
May 23 14:53:03 RT-AC86U-xxxx admin: VPN Client 1 going down ...
May 23 14:53:03 RT-AC86U-xxxx VPN Client 1 is not connected
May 23 14:53:03 RT-AC86U-xxxx VPN Client 3 is connected for 1 days, 14 hours 13 minutes 30 seconds
May 23 14:53:08 RT-AC86U-xxxx admin: VPN Client 1 coming up ...
May 23 14:53:08 RT-AC86U-xxxx VPN Client 1 is connected for 0 days, 00 hours 00 minutes 00 seconds
May 23 14:53:08 RT-AC86U-xxxx VPN Client 3 is connected for 1 days, 14 hours 13 minutes 35 seconds
May 23 15:00:00 RT-AC86U-xxxx VPN Client 1 is connected for 0 days, 00 hours 06 minutes 52 seconds
May 23 15:00:00 RT-AC86U-xxxx VPN Client 3 is connected for 1 days, 14 hours 20 minutes 27 seconds
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top