From: Johannes Truschnigg Date: Mon, 14 Mar 2022 20:25:51 +0000 (+0100) Subject: Implement link load estimation X-Git-Url: https://johannes.truschnigg.info/gitweb/?a=commitdiff_plain;h=01f65776c8eeeef25544df28d217b68de635d6f2;p=sqm_lagthrottle Implement link load estimation --- diff --git a/__lagdetect.awk b/__lagdetect.awk index 58e1a1b..b21da82 100644 --- a/__lagdetect.awk +++ b/__lagdetect.awk @@ -6,6 +6,8 @@ BEGIN { print "# PINGSLOTS=" PINGSLOTS print "# BW_MAX=" BW_MAX print "# BW_MIN=" BW_MIN + print "# FILE_TX=" FILE_TX + print "# FILE_RX=" FILE_RX split(PING_PEERS, pps, " ") for (pp in pps) { pn = pps[pp] @@ -18,6 +20,7 @@ BEGIN { ping_pprev[pn]=-1 # latency recorded in the previous cycle not_increasing_count[pn]=0 # number of consecutive cycles with no (fudged) latency increase } + update_bw() } @@ -27,6 +30,7 @@ BEGIN { seq=$3 bytes=0 lat=9999 + update_bw() # XXX TODO what now? process_record(pn, bytes, lat) #print "TIMEOUT for " pn @@ -39,9 +43,47 @@ BEGIN { seq=$3 bytes=$4 lat=$6 + update_bw() process_record(pn, bytes, lat) } +function update_ts() { + ts = get_time() + if( (ts - ts_old) < 0.1 ) { + return 0 + } + ts_old = ts + return 1 +} + + +function get_time() { + getline upt < "/proc/uptime" + close("/proc/uptime") + split(upt,ts," ") + return ts[1] +} + +function update_bw() { + if (! (update_ts())) { + #print "too fast, skiping bw reads " ts - ts_old + return + } + + tx_old=tx + rx_old=rx + + getline tx < FILE_TX + close(FILE_TX) + + getline rx < FILE_RX + close(FILE_RX) + + rxdelta=(rx - rx_old) + txdelta=(tx - tx_old) + #print "rx_delta=" rxdelta " tx_delta=" txdelta +} + function process_record(pn, bytes, lat) { if (! (pn in slotindex)) { diff --git a/lagdetect.sh b/lagdetect.sh index 46e3d9c..d9cd0e5 100755 --- a/lagdetect.sh +++ b/lagdetect.sh @@ -2,10 +2,12 @@ THRESHOLD=1.2 FUDGE_MS=5.0 PING_PEERS='1.1.1.1 8.8.8.8' -PING_GW_IPV4=yes +PING_GW_IPV4=no PING_GW_IPV6=no PING_SLOTS_PER_PEER=5 PING_INTERVAL=500 +FILE_RX='/sys/class/net/eth1/statistics/rx_bytes' +FILE_TX='/sys/class/net/eth1/statistics/tx_bytes' @@ -106,6 +108,8 @@ set -u fping --loop --retry=1 --size=1280 --period="${PING_INTERVAL}" --random ${PING_PEERS} 2>/dev/null \ | awk \ + -v FILE_RX="${FILE_RX}" \ + -v FILE_TX="${FILE_TX}" \ -v THRESHOLD="${THRESHOLD}" \ -v PINGSLOTS="${PING_SLOTS_PER_PEER}" \ -v FUDGE="${FUDGE_MS}" \