Browse Source

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 <fe@dev.tdt.de>
lilik-openwrt-22.03
Florian Eckert 6 years ago
parent
commit
1236003733
2 changed files with 13 additions and 1 deletions
  1. +9
    -1
      net/mwan3/files/usr/libexec/rpcd/mwan3
  2. +4
    -0
      net/mwan3/files/usr/sbin/mwan3track

+ 9
- 1
net/mwan3/files/usr/libexec/rpcd/mwan3 View File

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


+ 4
- 0
net/mwan3/files/usr/sbin/mwan3track View File

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


Loading…
Cancel
Save