bandmon/Bash/OpenWrt/band.bash
2021-05-03 22:32:57 -05:00

21 lines
874 B
Bash

#!/bin/bash
# Requires vnstat to be running on target system
# initial values
# Note comcast caps at 1.2 TB
mtotal=1000 # Monthly warning threshold
dmax=40 # daily max usage value, trouble might arise if I go past 40 GB a day
md=`date +%d` # day of the month numerically
cmd=$(($dmax * $md)) # computed max daily, not hard value but can indicate a problem
wif="eth1.2" # interface to ask vnstat for, in my case the default wan vlan in Openwrt
# now vnstat stuff, some of this is specific to openwrt
vnhourly=`vnstat -i $wif -d -s --oneline | awk -F\; '{print $6}'` # total daily usage
vnmonthly=`vnstat -i $wif -d -s --oneline | awk -F\; '{print $11}'` # monthly total usage
logger "dom $md cm $cmd vnhourly $vnhourly vnmonthly $vnmonthly"; # Remeber the local syslog on OpenWrt is setup to log to a remote system
# therefore this is a lazy way to send the data out