I figured out a way to extend Petrica’s implementation to include wan transmit and receive speed using the script in pnakashian’s link. Mbit/s is used to match what the ASUSWRT integration. Warning, this works for me but I’m new to SNMP so please feel free to let me know if I did something wrong.
You’ll need the following 2 scripts which are almost identical except for the last line. There’s probably a more elegant way to do this with just 1 script and passing a variable but I wasn’t sure how to do that when calling the script though SNMP.
NOTE: The scripts will produce errors the first few times as they need to create /tmp/ files. This was also the case with the original script.
download.sh
#!/bin/sh
maxint=4294967295
scriptname=${0##*/}
old="/tmp/$scriptname.data.old"
new="/tmp/$scriptname.data.new"
old_epoch_file="/tmp/$scriptname.epoch.old"
old_epoch=`cat $old_epoch_file`
new_epoch=`date "+%s"`
echo $new_epoch > $old_epoch_file
interval=`expr $new_epoch - $old_epoch` # seconds since last sample
if [ -f $new ]; then
awk -v old=$old -v interval=$interval -v maxint=$maxint '{
getline line < old
bytes = $1 - line
if(bytes < 0) {bytes = bytes + maxint}
mbps = (8 * (bytes) / interval) / 1024 / 1024 # mbits per second
printf "%.2f \n", mbps
}' $new
mv $new $old
fi
cat /proc/net/dev | tail -1 | tr ':|' ' ' | awk '{print $2}' > $new
upload.sh
#!/bin/sh
maxint=4294967295
scriptname=${0##*/}
old="/tmp/$scriptname.data.old"
new="/tmp/$scriptname.data.new"
old_epoch_file="/tmp/$scriptname.epoch.old"
old_epoch=`cat $old_epoch_file`
new_epoch=`date "+%s"`
echo $new_epoch > $old_epoch_file
interval=`expr $new_epoch - $old_epoch` # seconds since last sample
if [ -f $new ]; then
awk -v old=$old -v interval=$interval -v maxint=$maxint '{
getline line < old
bytes = $1 - line
if(bytes < 0) {bytes = bytes + maxint}
mbps = (8 * (bytes) / interval) / 1024 / 1024 # mbits per second
printf "%.2f\n", mbps
}' $new
mv $new $old
fi
cat /proc/net/dev | tail -1 | tr ':|' ' ' | awk '{print $10}' > $new
- platform: snmp
host: my_ip
community: public
baseoid: 1.3.6.1.2.1.25.1.17.3.1.1.8.100.111.119.110.108.111.97.100 # Found via snmpwalk, but looks unusually long
name: bespin_download_speed_negative # Negative value looks better in history graph
accept_errors: true
default_value: 0
version: 2c
value_template: '-{{value | float | round (2)}}'
unit_of_measurement: 'Mbit/s' # Use the same units as the ASUSWRT integration
scan_interval: 15
- platform: snmp
host: my_ip
community: public
baseoid: 1.3.6.1.2.1.25.1.18.3.1.1.6.117.112.108.111.97.100
name: bespin_upload_speed
accept_errors: true
default_value: 0
version: 2c
value_template: '{{value | float | round (2)}}'
unit_of_measurement: 'Mbit/s' # Use the same units as the ASUSWRT integration
scan_interval: 15
This is tested on an ASUS RT-AX86U. If it’s not working on your router then it could be that the order of devices in /proc/net/dev is different.