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 <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2018-10-09 08:32:03 +02:00
parent 1236003733
commit 1ee9fb4aff
2 changed files with 13 additions and 1 deletions

View file

@ -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")"

View file

@ -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