Persistent traffic log and more in OpenWRT

OpenWRT provides some usage statistics out of the box. But wouldn't it be nice to have persistent traffic/bandwith usage logs? Maybe even CPU usage, Wifi signal quality or even Ping time logs to monitor the availability of your own website? Sadly the graphs you get are nowhere near as nice as the ones provided by OpenWRT...

I assume you are using the graphical OpenWRT frontend Luci. I rely on it for configuring the logging daemon.

1. Enable USB stick support in OpenWRT
2. Automounting the USB stick on boot
3. Set up the logging process

Enable USB stick support in OpenWRT

You need to have formatted your stick with an ext4 partition for this.

  1. SSH into your router.
  2. Install the required/usefull packages:
    opkg update
    # USB support for the linux kernel:
    opkg install kmod-usb-core
    # USB 2 support:
    opkg install kmod-usb2
    # ext4 support:
    opkg install kmod-fs-ext4
    # for mounting on startup and hotplug:
    opkg install block-mount
    # good for listing (usb) devices
    opkg install fdisk
    # the text editor we use
    opkg install nano
    • If you still use USB 1.1:
      # there are two USB 1.1 chip versions,
      # we simply install both modules:
      opkg install kmod-usb-uhci
      opkg install kmod-usb-ohci
  3. Reboot to load all kernel modules:

Automounting the USB stick on boot

  1. Plug in your USB-stick.
  2. Find the UUID of your stick:
    fisk -l
    Look at the listed Devices in the last few lines. Look for the entry whose Size column fits the ext4 partition of your stick.
    Lets assume your partition was listed as /dev/sda1.
  3. Get the UUID:
    block info /dev/sda1
    Memorize the first few characters of the UUID.
  4. Set up boot-time automounting:
    nano /etc/fstab
    • If the file is empty do the following:
      1. Close nano:
        Press CTRL + x
      2. Generate a fstab file:
        block detect > /etc/config/fstab
  5. Look for the config block with your UUID.
  6. Change the value behind option target to lets say /mnt/usb1.
  7. Change the value behind option enabled to 1.
  8. Save the file.
  9. Enable fstab:
    /etc/init.d/fstab enable
  10. Create the mount directory:
    mkdir /mnt/usb1
  11. Manually mount the stick:
    /sbin/block mount
  12. Make sure the access rights are correct:
    chown root:root /mnt/usb1
    chmod 755 /mnt/usb1

Set up the logging process

  1. Still on your router:
  2. Install packages through the meta-package for the grafical frontend luci:
    opkg install luci-app-statistics
    • If you do not intend to use luci you can install collectd manually:
      opkg install collectd collectd-mod-rrdtool collectd-mod-iwinfo collectd-mod-interface collectd-mod-load collectd-mod-network
      If you do not use luci your on your own after here. The OpenWRT-Wiki article may be of help for you.
  3. Generate a storage folder on our USB stick:
    mkdir /mnt/usb1/statistics
  4. Open the webfrontend of OpenWRT in your browser.
  5. Go to StatisticsCollectdOutput pluginsRRDTool.
  6. Change Storage directory to /mnt/usb1/statistics
  7. Click Save & Apply.
  8. Go to Network plugins.
  9. There you can select what interfaces should be logged. I recommend just logging everything except loopback lo:
    Click on lo and check Monitor all except specified.
  10. Click Save & Apply.

Most of the now installed logging capabilites are enabled by default. You can deactivate individual logs in the submenus of StatisticsCollectd. But you can also install even more! See all available options by entering opkg list collectd-mod-*.

You can now view your collected data under StatisticsGraphs!

1. OpenWRT: Monitoring using collectd (
2. USB Basic Support (
3. USB Storage (
4. Mounting Block Devices (
5. Fstab Configuration (
6. Collectd (

The author

Written by Per

Free software enthusiast and transhumanist residing in Stuttgart, Germany.

comments powered by Disqus