Coder Social home page Coder Social logo

Accessing Vnstat figures about vnstat HOT 2 CLOSED

kds54 avatar kds54 commented on August 26, 2024
Accessing Vnstat figures

from vnstat.

Comments (2)

kds54 avatar kds54 commented on August 26, 2024

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.

from vnstat.

vergoh avatar vergoh commented on August 26, 2024

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:

  1. Assuming OpenWRT has implemented also the json api, you could query it via http(s) and get that information remotely. If this hasn't been made available then maybe a feature request towards OpenWRT could help.
  2. With command line access you can query 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.
  3. With command line access, instead of --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
  4. Read the vnstat.db sqlite file directly with sqlite cli or python. I wouldn't however suggest using this method.

Things not suggested to be done:

  1. OCR with the image
  2. Parsing any "intended for humans" plain text vnstat output

from vnstat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.