net/mwan3: add uptime ubus information
authorFlorian Eckert <fe@dev.tdt.de>
Thu, 4 Oct 2018 07:36:50 +0000 (09:36 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Fri, 12 Oct 2018 06:15:33 +0000 (08:15 +0200)
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 <fe@dev.tdt.de>
net/mwan3/files/usr/libexec/rpcd/mwan3
net/mwan3/files/usr/sbin/mwan3track

index eb5f98ce5d5988a87d229e29ad04db394c553d07..a4b33efd17bb6479159073e9c4d95a8d1e2dbd2f 100755 (executable)
@@ -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")"
index c2ebb3e9f5008b10d6f03cb449d790d676b6f6b8..725e1086dfe4c89307889a533f8e45e401379bf9 100755 (executable)
@@ -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