net/mwan3: expand ubus to show when last mwan3track check was done
authorFlorian Eckert <fe@dev.tdt.de>
Mon, 31 Jul 2017 11:57:51 +0000 (13:57 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Thu, 10 Aug 2017 09:30:47 +0000 (11:30 +0200)
To know how old the ubus output is, add an age parameter which indicats
how old the check informations on the interface are.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/mwan3/files/usr/libexec/rpcd/mwan3
net/mwan3/files/usr/sbin/mwan3track

index 1342894b6674e43e9c305261891495102e7ca3f0..6bb6f8dd179307d192faaef019813a9271c9be9a 100755 (executable)
@@ -34,7 +34,8 @@ get_mwan3_status() {
        local iface="${1}"
        local iface_select="${2}"
        local running="0"
-       local pid device
+       local age=0
+       local pid device time_p time_n
 
        network_get_device device $1
 
@@ -44,7 +45,14 @@ get_mwan3_status() {
                        running="1"
                fi
 
+               time_p="$(cat "$MWAN3_STATUS_DIR/${iface}/TIME")"
+               [ -z "${time_p}" ] || {
+                       time_n="$(date +'%s')"
+                       let age=time_n-time_p
+               }
+
                json_add_object "${iface}"
+               json_add_int age "$age"
                json_add_string "score" "$(cat "$MWAN3_STATUS_DIR/${iface}/SCORE")"
                json_add_string "lost" "$(cat "$MWAN3_STATUS_DIR/${iface}/LOST")"
                json_add_string "turn" "$(cat "$MWAN3_STATUS_DIR/${iface}/TURN")"
index f9909dd0e9ac7f1ec63878a936b9b723f2d4a33c..bdb793b592d2e80fe9b8e40514bac3133f54e19e 100755 (executable)
@@ -154,6 +154,7 @@ main() {
                echo "${lost}" > /var/run/mwan3track/$1/LOST
                echo "${score}" > /var/run/mwan3track/$1/SCORE
                echo "${turn}" > /var/run/mwan3track/$1/TURN
+               echo "$(date +'%s')" > /var/run/mwan3track/$1/TIME
 
                host_up_count=0
                sleep "${sleep_time}" &