aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2018-10-04 09:36:50 +0200
committerFlorian Eckert <fe@dev.tdt.de>2018-10-12 08:15:33 +0200
commit12360037332176f9a286ec754d340a9721479abf (patch)
tree9059846be6ca742bc170f7cc256b3901cddf95c5 /net
parent3a5c3e03e2b4eb08ce0a0bc2d1b5d7790ebc1705 (diff)
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>
Diffstat (limited to 'net')
-rwxr-xr-xnet/mwan3/files/usr/libexec/rpcd/mwan310
-rwxr-xr-xnet/mwan3/files/usr/sbin/mwan3track4
2 files changed, 13 insertions, 1 deletions
diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3
index eb5f98ce5..a4b33efd1 100755
--- a/net/mwan3/files/usr/libexec/rpcd/mwan3
+++ b/net/mwan3/files/usr/libexec/rpcd/mwan3
@@ -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")"
diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track
index c2ebb3e9f..725e1086d 100755
--- a/net/mwan3/files/usr/sbin/mwan3track
+++ b/net/mwan3/files/usr/sbin/mwan3track
@@ -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