Skip to content

Commit

Permalink
Merge pull request #57 from Freifunk-Dresden/se-sysinfo2
Browse files Browse the repository at this point in the history
sysinfo: add details network statisitc
  • Loading branch information
cremesk committed Jan 8, 2024
2 parents 90ea3a4 + 16c1858 commit 2ea837b
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions salt/freifunk/base/ddmesh/var/www_freifunk/sysinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ function combined_statistics() {

stat_wan_rx=0
stat_wan_tx=0
stat_backbone_mesh_rx=0
stat_backbone_mesh_tx=0
stat_gateway_rx=0
stat_gateway_tx=0
stat_backbone_mesh_wg_rx=0
stat_backbone_mesh_wg_tx=0
stat_backbone_mesh_fastd_rx=0
stat_backbone_mesh_fastd_tx=0
stat_vpn_rx=0
stat_vpn_tx=0

Expand All @@ -56,16 +56,31 @@ function combined_statistics() {
net=${entry%%=*}
net=${net#net_}
ifname=${entry#*=}
ifname=${ifname/+/}

[ -n "$ifname" ] && ifname="$(basename /sys/class/net/${ifname}*)"
# on router (openwrt network/firewall specific):
# wg uses tbbwg+ as interface name for all single interfaces
# as long as we do not support wireguard vpn exit on router
# I have to keep '+' in interface name. (openvpn was removed because of huge resource demands)
# on server: n/a
# ifname=${ifname/+/}


[ -n "$ifname" ] && ifname="$(basename /sys/class/net/${ifname})"
[ -z "$ifname" ] && continue
ifpath="/sys/class/net/${ifname}"

if [ -n "${ifname}" -a -d ${ifpath} ]; then

rx="$(cat ${ifpath}/statistics/rx_bytes)"
tx="$(cat ${ifpath}/statistics/tx_bytes)"

# fix statistic when no connections is established
# e.g. fastd
if [ "$rx" = "0" -o "$tx" = "0" ]; then
rx="0"
tx="0"
fi

# collect data
case "$net" in
wan)
Expand All @@ -74,16 +89,14 @@ function combined_statistics() {
;;

# use tbbwg main wireguard interface to cover all ipip tunnels
backbone_wg|backbone_fastd)
# fix fastd statistic when no connections is established
test ${net} = "tbb_fastd" -a "$rx" = "0" && tx="0"
stat_backbone_mesh_rx=$((stat_backbone_mesh_rx + rx))
stat_backbone_mesh_tx=$((stat_backbone_mesh_tx + tx))
backbone_wg)
stat_backbone_mesh_wg_rx=$((stat_backbone_mesh_wg_rx + rx))
stat_backbone_mesh_wg_tx=$((stat_backbone_mesh_wg_tx + tx))
;;

ffgw)
stat_gateway_rx=$((stat_gateway_rx + rx))
stat_gateway_tx=$((stat_gateway_tx + tx))
backbone_fastd)
stat_backbone_mesh_fastd_rx=$((stat_backbone_mesh_fastd_rx + rx))
stat_backbone_mesh_fastd_tx=$((stat_backbone_mesh_fastd_tx + tx))
;;

vpn1|vpn2)
Expand All @@ -94,16 +107,23 @@ function combined_statistics() {
fi
done

stat_backbone_mesh_rx=$((stat_backbone_mesh_wg_rx + stat_backbone_mesh_fastd_rx))
stat_backbone_mesh_tx=$((stat_backbone_mesh_wg_tx + stat_backbone_mesh_fastd_tx))

# output
cat << EOM
"wan_rx":"${stat_wan_rx}",
"wan_tx":"${stat_wan_tx}",
"backbone_mesh_rx":"${stat_backbone_mesh_rx}",
"backbone_mesh_tx":"${stat_backbone_mesh_tx}",
"gateway_rx":"${stat_gateway_rx}",
"gateway_tx":"${stat_gateway_tx}",
"vpn_rx":"${stat_vpn_rx}",
"vpn_tx":"${stat_vpn_tx}"
"vpn_tx":"${stat_vpn_tx}",
"details": {
"backbone_mesh_wg_rx":"${stat_backbone_mesh_wg_rx}",
"backbone_mesh_wg_tx":"${stat_backbone_mesh_wg_tx}",
"backbone_mesh_fastd_rx":"${stat_backbone_mesh_fastd_rx}",
"backbone_mesh_fastd_tx":"${stat_backbone_mesh_fastd_tx}"
}
EOM
}

Expand Down

0 comments on commit 2ea837b

Please sign in to comment.