Shell scripts for bandwidth monitoring on AsusWRT-Merlin routers.
| File | Purpose |
|---|---|
| bwmon.sh | Core monitoring script - uses iptables to count traffic |
| S80bwmon | Init script - manages cron jobs for scheduled updates |
| install.sh | Installer - sets up dependencies and copies files |
| uninstall.sh | Clean removal of all installed files |
| sample-lighttpd-index.html | Sample landing page for lighttpd |
- AsusWRT-Merlin router
- Entware package manager
- lighttpd web server (installed automatically)
- bc calculator (installed automatically)
- iptables chain (
RRDIPT) counts bytes per IP address - Cron job runs every 30 minutes to collect data
- ARP table (
/proc/net/arp) identifies connected devices - User resolution maps MAC/IP to usernames via:
/etc/hosts.dnsmasq/etc/dnsmasq/hosts/hosts/etc/hosts- NVRAM
custom_clientlist
Router Traffic
│
▼ (iptables RRDIPT chain)
bwmon.sh update
│
▼ (writes)
usage.db ──► lighttpd ──► React Frontend
bwmon.sh setup <path> # Create iptables rules
bwmon.sh update <path> # Collect data and publish
bwmon.sh publish <path> # Publish without collecting/opt/etc/init.d/S80bwmon start # Start cron jobs
/opt/etc/init.d/S80bwmon stop # Stop cron jobs
/opt/etc/init.d/S80bwmon restart # Restart service
/opt/etc/init.d/S80bwmon check # List active cron jobs| Job | Frequency | Purpose |
|---|---|---|
| bwmon_setup | Every 1 minute | Ensure iptables rules exist |
| bwmon_update | Every 30 minutes | Collect and publish data |
YYYY-MM,MAC,IP,USAGE_IN,USAGE_OUT,CREATE_TIME,UPDATE_TIME
Served to the React frontend:
YYYY-MM,IP,MAC,USER,USAGE_IN,USAGE_OUT,CREATE_TIME,UPDATE_TIME
- Usage values are in kilobytes
- Times are Unix timestamps
- POSIX shell only - No bash-isms (runs on router's busybox shell)
- Use
bcfor math - Shell has no built-in arithmetic for large numbers - File locking - Uses
/tmp/bwmon.lockto prevent concurrent updates - Flow Cache - Disabled automatically for accurate packet counting
| Source | Destination |
|---|---|
| bwmon.sh | /opt/share/bwmon/ |
| S80bwmon | /opt/etc/init.d/ |
| react/build/* | /opt/share/www/bwmon/ |
| sample-lighttpd-index.html | /opt/share/www/ |
Log file: /opt/var/log/bwmon.log
For installation instructions, see the main README.md.