From 1ee9fb4aff3ee78ab015a32de0a3ab1e594210bf Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Tue, 9 Oct 2018 08:32:03 +0200 Subject: [PATCH] net/mwan3: add downtime ubus information Get downtime information for the tracked mwan3 wan interfaces. The information shows how long this interface is in disconnected 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 a4b33efd1..a9b31f222 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -37,7 +37,8 @@ get_mwan3_status() { local running="0" local age=0 local uptime=0 - local pid device time_p time_n time_u + local downtime=0 + local pid device time_p time_n time_u time_d network_get_device device $1 @@ -59,9 +60,16 @@ get_mwan3_status() { let uptime=time_n-time_u } + time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/DOWNTIME")" + [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { + time_n="$(get_uptime)" + let downtime=time_n-time_d + } + json_add_object "${iface}" json_add_int age "$age" json_add_int uptime "${uptime}" + json_add_int downtime "${downtime}" 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 725e1086d..420878472 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -109,9 +109,11 @@ main() { if [ "$STATUS" = "unknown" ]; then echo "unknown" > /var/run/mwan3track/$1/STATUS echo "0" > /var/run/mwan3track/$1/UPTIME + echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME score=0 else echo "online" > /var/run/mwan3track/$1/STATUS + echo "0" > /var/run/mwan3track/$1/DOWNTIME echo "$(get_uptime)" > /var/run/mwan3track/$1/UPTIME env -i ACTION="connected" INTERFACE="$1" DEVICE="$2" /sbin/hotplug-call iface fi @@ -202,6 +204,7 @@ main() { if [ $score -eq $up ]; then echo "offline" > /var/run/mwan3track/$1/STATUS echo "0" > /var/run/mwan3track/$1/UPTIME + echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME $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 @@ -243,6 +246,7 @@ main() { if [ "${IFDOWN_EVENT}" -eq 1 ]; then echo "offline" > /var/run/mwan3track/$1/STATUS + echo "$(get_uptime)" > /var/run/mwan3track/$1/DOWNTIME 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