Closed kds54 closed 2 months ago
I have solved. this problem. Thanks to everyone that viewed.
I am connecting top the router from a Raspberry Pi using SSH. Using the command:
ssh_client.exec_command("cd /usr/bin") stdin,stdout,stderr = ssh_client.exec_command("vnstat -m 1 --oneline")
I then slice the output to grab the necessary information and port it to my MQTT broker.
It would be polite to also explain your solution. There aren't that many more annoying things on the Internet than looking for a solution for a problem, finding out someone else has also been having the same problem and solved it but without telling how.
For your specific scenario, there are several options depending on what is most suitable for the followup implementation:
vnstat --json m 1 -i wan
for getting the output for only the currently ongoing month in json format for the wanted interface (wan in this case). Then extend this with jq
to get the sum of rx and tx values resulting in the full command being vnstat --json m 1 -i wan | jq .interfaces[0].traffic.month[0].rx+.interfaces[0].traffic.month[0].tx
. Obviously if you are using python to read the vnstat
command output then there's no point using jq
for parsing the correct content since python will be more than capable on doing that too.--json
, use --oneline
instead and extra the 11th field containing the current monthly data and instruct --oneline
to use bytes: vnstat --oneline b -i wan | cut -d\; -f11
Things not suggested to be done:
vnstat
output
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