To jest stara wersja strony!
Dodajemy dwie reguły firewalla oraz przenosimy je na samą górę:
/ip firewall filter add action=passthrough chain=forward comment=WAN-IN in-interface=ether1 add action=passthrough chain=forward comment=WAN-OUT out-interface=ether1
Gdzie ether1 to nasz WAN
Dodajemy skrypt:
/system script add dont-require-permissions=no name=wanusage owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="# /ip firewall filter\r\ \n#add action=passthrough chain=forward comment=WAN-IN in-interface=ether1\r\ \n#add action=passthrough chain=forward comment=WAN-OUT out-interface=ether1\r\ \n\r\ \n:local BYTESOUT [/ip firewall filter get [/ip firewall filter find comment=\"WAN-OUT\"] bytes]\r\ \n:local BYTESIN [/ip firewall filter get [/ip firewall filter find comment=\"WAN-IN\"] bytes]\r\ \n\r\ \n# Setting variables\r\ \n:local curDate [/system clock get date]\r\ \n:local curYear [:pick \$curDate 7 13]\r\ \n:local curMon [ :pick \$curDate 0 3 ]\r\ \n:local curDay [:pick \$curDate 4 6]\r\ \n:local CURRENTDATE \"\$curYear-\$curMon-\$curDay\"\r\ \n:local FILENAME \"\$curYear\$curMon.txt\"\r\ \n\r\ \n:if ([:len [/file find name=\$FILENAME]] > 0) do={\r\ \n/file set \"\$FILENAME\" contents=([get \$FILENAME contents] . \"\$CURRENTDATE;=\$BYTESIN/1024/1024/1024;=\$BYTESOUT/1024/1024/1024\\r\\n\")\r\ \n} else {\r\ \n/file print file=\$FILENAME\r\ \n/delay delay-time=2\r\ \n/file set \"\$FILENAME\" contents=\"Data;Download (bytes) GB;Upload (bytes) GB\\r\\n\$CURRENTDATE;=\$BYTESIN/1024/1024/1024;=\$BYTESOUT/1024/1024/1024\\r\\n\"\r\ \n}\r\ \n\r\ \n/ip firewall filter reset-counters [find comment=\"WAN-IN\" ]\r\ \n/ip firewall filter reset-counters [find comment=\"WAN-OUT\" ]\r\ \n"
W schedulerze ustawiamy czas cyklicznego uruchomienia się:
/system scheduler add interval=1d name=wanstats on-event="/system script run wanusage" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=dec/03/2018 start-time=23:59:55
Raz na 24h będzie generował się plik, w którym będą dane ściągniętych i wysłanych GB. Nie usuwajmy pliku - wartości będą się dopisywać.