VNStat

An inquiry was made recently about keeping track of data usage for WAN connections that have usage caps or fees: List of current feature requests 2022 - #137 by Theodopolus

I’m sort of curious myself so I thought I would start a topic on VNStat, which keeps track of router statistics with what appears to be a light footprint. I started with my Mango.

  1. With Luci installed, install vnstat, vnstati, and the luci-app-vnstat. I had no difficulty with my Mango, and it picked up both the WISP interface and the internal bridge interface. It generates tables and charts with daily, monthly and all-time traffic. This is the 1.18 version for 19.07. There is a 2.x version for the next go round that will use sqlite.
  2. A downside is that the database is in temp space, so it disappears at each reboot. Follow the directions here: [OpenWrt Wiki] Network Traffic Monitor with vnStat to change the update interval to five minutes from the default one minute, start the daemon. Then follow Method 2 on that page to have a cron save the database to flash every six hours.

That seems to preserve the data on a reboot. I haven’t tried to see if the database is recovered to the last backup when you just unplug the router.

Things I haven’t figured out:

  1. Adding a script using curl to email the stats daily. That’s something a script on my Asus does.
  2. Adding a script that computes usage against a maximum bandwidth. Also something my Asus does.
  3. In a script, recomputing usage from base 1024 (how VNStat computes usage) to base 1000 (how ISPs compute usage).

Maybe others want to tackle those.

Trying to get to here, the email I get each day from my Asus:

You have used 9.78% (488.88GB) of your 5000.00GB cycle allowance; the next cycle starts on day 1 of the month.
image

3 Likes

Thanks for sharing.

Very helpful.

Thanks for starting this @elorimer.

I am afraid that I know ‘not a lot’ of the scripting languages, or how to access OpenWrt using them, so will watch this thread with interest.

I do know Node-RED and have used REST API’s for that and other things. FYI Router I have is GL-X750V2 (Spitz)

I have a Node-RED flow that is able to access WAN signal strength and the available WiFi networks available, so I might be able to develop that further, but then I would need to be able to store the historic data. This is ‘doable’ as I have an RPI running on the Network already (PiHole).

I have installed VnStat and am running it to see what data is available.

I tried installing this to my convexa and the flint and i get an error when attempting to install through gl.inet gui (both on latest stable firmware)

Try to install in Luci?

1 Like

Read here, there are more Bandwith Monitor also for Luci.

I have installed wrtbwmon and luci-wrtbwmon

How to:

wrtbwmon

Also I tried luci-app-nbwmon (Netlink Bandwidth Monitor)

1 Like

Stuck at the moment with curl. Everytime I try to send an email with a configuration that works in other environments, I get a 48 error, suggesting a mismatch between curl and libcurl; maybe this version of curl isn’t compiled with SMTP.

Also, not sure where to find the nice pix vnstati creates to attach to the email.

EDIT: Ok, I’ve got this partially working with msmtp instead of curl.

@elorimer I am still looking, but came across this thread on OpenWrt. Don’t know if that will help at all.

@alzhao Is it possible to get the Upload and Download figures from the Modem connection status box on the Internet page of GL.iNet Admin added to the GL.iNet REST API? Or give a clue as to where they are obtained from? Thank you.

We are not maintaining API v3.x as we are working on v4.x.
V3.x modem traffic is not accurate and accumulated.

You mentioned API v4.x in a previous thread from October and I understand that you will not be developing API v3 any longer. Have you any idea when v4.x might be available to use?

I’ve made some progress with this but I’m puzzled over the interfaces I want to monitor. I’m thinking I really only want stats from my WAN connection, whether that is tethered over a 3G/4G phone or wired to the WAN port or with a WISP connection to my home wifi. At the moment I’m only using the WISP function.

In LuCI, Vnstat is giving me these choices:

apcli0 (wwan, ethernet)
br-lan (lan)
eth0 (switch)
eth0.1 (lan)
eth0.2 (wan, wan6)
ra0 (ethernet)

From the parentheticals I thought I should be looking at apcli0 and / or eth0.2, but after several days there is zero traffic on apcli0, and only transmitted traffic on eth0.2. I’m guessing apcli0 may be solely for USB tethering, so that is okay, but I thought I should see much more received traffic.

On ra0 I have a lot of received/transmitted traffic.

Thoughts?

Unfortunately, my Router is used in the Motorhome and we are now at home for a while. I did manage to start getting stats, but have yet to understand how they all relate to each other. I do have a Router here with OpenWrt installed, I will have a go with that, but is is only used as a wifi extender.