From 12360037332176f9a286ec754d340a9721479abf Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 4 Oct 2018 09:36:50 +0200 Subject: [PATCH] net/mwan3: add uptime ubus information Get uptime information for the tracked mwan3 wan interfaces. The information shows how long this interface is in connected state. Signed-off-by: Florian Eckert --- net/mwan3/files/usr/libexec/rpcd/mwan3 | 10 +++++++++- net/mwan3/files/usr/sbin/mwan3track | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index eb5f98ce5..a4b33efd1 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -36,7 +36,8 @@ get_mwan3_status() { local iface_select="${2}" local running="0" local age=0 - local pid device time_p time_n + local uptime=0 + local pid device time_p time_n time_u network_get_device device $1 @@ -52,8 +53,15 @@ get_mwan3_status() { let age=time_n-time_p } + time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/UPTIME")" + [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { + time_n="$(get_uptime)" + let uptime=time_n-time_u + } + json_add_object "${iface}" json_add_int age "$age" + json_add_int uptime "${uptime}" json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")" json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")" json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")" diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index c2ebb3e9f..725e1086d 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -108,9 +108,11 @@ main() { if [ "$STATUS" = "unknown" ]; then echo "unknown" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/UPTIME score=0 else echo "online" > /var/run/mwan3track/$1/STATUS + echo "$(get_uptime)" > /var/run/mwan3track/$1/UPTIME env -i ACTION="connected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface fi while true; do @@ -199,6 +201,7 @@ main() { if [ $score -eq $up ]; then echo "offline" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/UPTIME $LOG notice "Interface $1 ($2) is offline" env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface @@ -240,6 +243,7 @@ main() { if [ "${IFDOWN_EVENT}" -eq 1 ]; then echo "offline" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/UPTIME $LOG notice "Interface $1 ($2) is offline" env -i ACTION="disconnected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface score=0