Comments (5)
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.
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.
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.
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.
Thank you !!
i am getting the output now.
from vnstat.
Related Issues (20)
- Wrong date if you want to track the daily use HOT 5
- Pfsense retention HOT 1
- vnstat: no longer works after databases/sqlite3 disabled DQS HOT 2
- Database size growing at alarming rate. Best ways to curb it? HOT 18
- Vnstat virtual interface not appearing HOT 7
- New VLANs not discovered HOT 2
- 95th percentile bandwidth calculation HOT 18
- wrong stat data for some interface HOT 17
- Calculate Traffic when vnstat stopped! HOT 4
- how to recover the database when i modify the time and updae the database force HOT 2
- How to install latest version? HOT 6
- Publish to snap store HOT 7
- vnstat measures file sharing from one device to another as transmission HOT 3
- How to install vnstat 2.9+ on Debian Bookworm. HOT 4
- Wireguard interface disabled, can't enable HOT 3
- Reset db in version 2 HOT 2
- do not exit with non-zero exit code when using `--alert` flag and `Failed to open database "/var/lib/vnstat/vnstat.db" in read-only mode.` throws HOT 5
- Accessing Vnstat figures HOT 2
- Send interface traffic result periodically to external server (URL) to avoid writing in the device HOT 2
- No interface matching "XXX" found in database. HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vnstat.