Sharing a script I wrote for tracking monthly and daily total WAN traffic statistics. The script reads traffic counters from eth1, stores them in a JSON file, and presents the totals through the file names. These files are empty, it's their names that provide the values.
If you need per-IP traffic statistics, take a look at another script I wrote: viewtopic.php?t=185910
This is how it looks:
Key features
If you need per-IP traffic statistics, take a look at another script I wrote: viewtopic.php?t=185910
This is how it looks:
Key features
- Everything is local on the router. You don't need any external servers or software to collect or view the data. Just open WinBox and look at the Files window.
- Best if used with a USB flash drive to avoid any worries about write cycles. If your device doesn't support external storage, you could schedule the script to run less frequently at the expense of more statistics loss when unexpected reboots take place. The amount of data written is very small, a few hundred bytes.
- Detects manual traffic counters resets as long as Rx counters are less than previously stored Rx value. If you intend to reset the counters, just run the script manually right before and after the reset to retain maximum accuracy.
- Tested with RouterOS 7.18.2+. This is important because the script uses a some newer scripting features.
- RouterOS doesn't support floating point, therefore reporting accurracy is +/-1GB. Calculation and saving is done in bytes, so there are no repeated rounding losses. The rounding (or rather truncating) happens only at the last step when the report file is produced.
- Detects reboots by placing a marker file in the root directory which is a RAM/tmpfs disk on many devices; for devices with no RAM disk by default, set up your own and specify the path for the marker file.
- To retain maximum accuracy, run the script just before a manual reboot to collect the data.
- Install and format USB drive.
- Upload the provided rsc script file to the USB drive (e.g. via WinBox - Files).
- Schedule the script to run every hour (or however often you like) at x:59:59.
Code:
/system scheduleradd interval=1h name=traffic on-event="/import usb1-part1/traffic.rsc" policy=read,write,sensitive start-date=2025-04-10 start-time=20:59:59
Statistics: Posted by anserk — Wed Apr 30, 2025 3:32 am