Key features
- Everything is local on the router. You don't need any external servers or software to collect the data. You only need a computer to view the report.
- The script uses kid-control functionality in RouterOS, which has a nice bonus - tracking per IP bandwidth.
- I'm using it with a USB flash drive where I don't worry 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 collected data loss due to unexpected reboots).
Limitations
- Tested with RouterOS 7 only.
- Kid-control counts all inter-VLAN traffic, not just WAN. Potentially you could re-write the script and use something like viewtopic.php?t=168427 instead of kid-control.
- The HTML report (placed in the root of flash drive) has .txt extension - this is RouterOS limitation. You need to download the report from WinBox Files window and then remove .txt so that only .html is left. You could set up SFTP or FTP and use the fetch tool to rename it or upload/rename to another location on your network. There are some discussions about using the branding package for serving custom static web pages directly from the router. I haven't looked into that.
- RouterOS supports only integers, so report accuracy is +/-1GB. If you need more precision, you can modify the script to report in megabytes. Note, all 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 is generated.
How to use
- Enable bandwidth tracking in kid-control. With configuration below kid-control doesn't limit anything but starts tracking traffic.
Code: Select all
/ip kid-control add name=Monitor mon=0s-1d tue=0s-1d wed=0s-1d thu=0s-1d fri=0s-1d sat=0s-1d sun=0s-1d
- Install and format USB drive.
- Create a directory called "bandwidth" on it (the easiest way is to create a folder on your PC and drag into Winbox Files window). You can change the paths as needed by changing the script variables.
- Schedule the script to run every hour (or however often you like) at x:59:59. On the last day of the month at 23:59:59 the script will generate the final report for the month and won't touch it again. The next scheduled run will use the new month name for data files and the report.
Here is how the report looks like:
Edit: uploaded the revised script to address the new scripting date format and USB path.