Accessing Vnstat figures

I am running OpenWRT with Vnstat2 and the data that Vnstat collects is written to an external USB dirve (/mnt/sda1/vnstat). In this image, I can see the total bytes across the WAN port for the current month.

What I would like to do is to capture the month-to-date total (only the current month) and port it to my MQTT broker probably once a day. Can someone enlighten me as to where the data is stored and how I can access it. I can either build a script on the router or build a python script on the MQTT broker.

TIA

1 Like

Not related to OpenWrt, but fwiw it uses an SQLite db structure. GitHub presence is here

You can use /usr/bin/vnstat to output text stats. Use -? or --longhelp to see command line switches. So something like the below for current month stats (first is more readable, second is in a more easily parsed format).

root@OpenWrt:/usr/bin# vnstat -m 1

 wan  /  monthly

        month        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2024-04    249.67 GiB |   11.28 GiB |  260.95 GiB |    1.64 Mbit/s
     ------------------------+-------------+-------------+---------------
     estimated    473.99 GiB |   21.42 GiB |  495.41 GiB |
root@OpenWrt:/usr/bin# vnstat -m 1 --oneline
1;wan;2024-04-16;15.59 GiB;676.09 MiB;16.25 GiB;2.01 Mbit/s;2024-04;249.67 GiB;11.28 GiB;260.95 GiB;1.64 Mbit/s;3.30 TiB;146.42 GiB;3.44 TiB
2 Likes

This has been solved and many thanks to all who responded.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.