]> johannes.truschnigg.info Git - sqm_lagthrottle/commitdiff
Implement link load estimation
authorJohannes Truschnigg <johannes@truschnigg.info>
Mon, 14 Mar 2022 20:25:51 +0000 (21:25 +0100)
committerJohannes Truschnigg <johannes@truschnigg.info>
Mon, 14 Mar 2022 20:25:51 +0000 (21:25 +0100)
__lagdetect.awk
lagdetect.sh

index 58e1a1b0e15ee39e0132746ce184f34cc2c60daf..b21da82c34a647ff2696bdbc611f1ffe81f2c44d 100644 (file)
@@ -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)) {
index 46e3d9c0a4ef0cd2b85e6364ec05e585bb7201fe..d9cd0e549c6e9834ae1a5124fef8405a369bde64 100755 (executable)
@@ -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}" \