Coder Social home page Coder Social logo

output in mb about vnstat HOT 5 CLOSED

vergoh avatar vergoh commented on July 23, 2024
output in mb

from vnstat.

Comments (5)

vergoh avatar vergoh commented on July 23, 2024

That's a good question and I now realize that there's no obvious way of getting that sort of output without having the automatically adjusting unit already included. Originally, --oneline was implemented for scripting purposes but it lacks the possibility of getting all output in bytes instead of some automatic unit. It's nice for anything that displays the values directly but clumsy if some comparisons or calculations need to be done. That's something I'll have to fix in the next version.

There's however plenty of other output options to play with that are somewhat easy to parse depending on the used script or programming language. Usually, one of --json, --xml or --exportdb provides the necessary information without too much parsing. At least with Python, importing the --json output makes the task trivial but the same output isn't that nice to parse with a shell script.

Here's what I came up with for bash etc. that will continue to work even with version 2.0:
vnstat --xml m | egrep "month id.*$(date +"<year>%Y</year><month>%m</month>")" | cut -d\> -f9 | cut -d\< -f1

That will give you the monthly received data in kilobytes in vnStat versions 1.x (those that support --xml) and in bytes in version 2.x (none released yet).

A simpler version for versionx 1.x for getting "latest month":
vnstat --xml m | grep 'month id=' | head -n 1 | cut -d\> -f9 | cut -d\< -f1

Same for 2.x (the dump order is different):
vnstat --xml m | grep 'month id=' | tail -n 1 | cut -d\> -f9 | cut -d\< -f1

from vnstat.

Michel001 avatar Michel001 commented on July 23, 2024

Thanks for the reply.

I have 1.11 running. but it seems that i get no output.
i will try to update to 1.16 and see if it makes a difference.

from vnstat.

Michel001 avatar Michel001 commented on July 23, 2024

i have tried to update. (ubuntu 14.04)
did wget for 1.16
make didn't work.
i had to sudo apt-get build-dep vnstat
./configure
make install
it ran but still vnstat -v shows 1.11
output remains the same.

from vnstat.

vergoh avatar vergoh commented on July 23, 2024

Using ./configure without any parameters will cause the binaries to be installed to directories that aren't within the PATH by default. If you still have the source directory available where you executed those commands then start with make uninstall to remove those binaries that ended up in wrong locations. The execute ./configure --prefix=/usr --sysconfdir=/etc && make as instructed right at the beginning of the INSTALL file followed by make install. That should get the binary locations right.

The extra parameter support for --xml was added in version 1.14 which would explain why the command didn't work with 1.11.

from vnstat.

Michel001 avatar Michel001 commented on July 23, 2024

Thank you !!

i am getting the output now.

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.