Allow to set fix units output
eprodanov opened this issue · comments
Hello there!
I would like to ask about option to set fix output units. For example only in Mbit/s or only in kbit/s.
Thank you!
Could you describe if there's some specific use case in mind for this request or simply put: why would it be nice to have such configuration option?
Would this option apply to all outputs or only some of a certain type like the lists?
Is this about the textual output, image output or both?
Hello there!
Thank you very much for your answer!
I am using console version of vnstat for my php monitoring script (network part) and put results in DB. Once in 30 seconds I call script using crone like:
"vnstat -tr 2 -i enp0s25 | grep -iE "(rx|tx)" | awk {'print $2'}', $vnstat); //network load: $vnstat[0] - rx, $vnstat[1] - tx"
And, depending of load, I get kbits or Mbits, but I would like to set exactly Mbits and be very happy)
Sorry if my issue is stupid and have a great day =)
Try this: vnstat -i enp0s25 -tr 2 --json | jq '.rx.bytespersecond,.tx.bytespersecond'
Or directly in Mbit/s: vnstat -i enp0s25 -tr 2 --json | jq '.rx.bytespersecond/131072,.tx.bytespersecond/131072'
Thank you, but that didn't work for me:
parse error: Invalid numeric literal at line 1, column 9
jq seems does not like something..
Which version of vnStat do you have?
Does it produce json output with -tr 2 --json
?
$ vnstat -tr 2 --json
{"jsonversion":"1","vnstatversion":"2.9 beta1","interface":"eth0","sampletime":2,"rx":{"ratestring":"2.25 KB/s","bytespersecond":2304,"packetspersecond":11,"bytes":4609,"packets":22},"tx":{"ratestring":"1.39 KB/s","bytespersecond":1422,"packetspersecond":6,"bytes":2844,"packets":12}}
Sorry, I had an 1.15 version, updated to 2.8 and your code works perfect!
vnstat -i enp0s25 -tr 2 --json | jq '.rx.bytespersecond/131072,.tx.bytespersecond/131072' - works perfect for me.
Thank you very much and have a great day!