vergoh / vnstat

vnStat - a network traffic monitor for Linux and BSD
GNU General Public License v2.0
1.36k stars 120 forks source link

Dont work comand vnstat -w in vnstat 2.6 #192

Closed Ser4ph4 closed 3 years ago

Ser4ph4 commented 3 years ago

How do I get to see the weekly total in vnstat, the command vnstat -w does not work, can someone help me?

vergoh commented 3 years ago

The weekly output and few other features were removed in version 2.0:

However, in the 2.x versions, --begin and --end could be used to achieve something similar. As an example, with the command constructed as follow: vnstat -d --begin $(date --date="Monday -2 week" +"%Y-%m-%d") --end $(date --date="Monday -1 week -1 day" (the idea is to use the date command to get the beginning and end of the previous week, or any other time range)

you'd get:

 eth0  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-02-22     31.87 MB |   130.64 MB |   162.51 MB |      1.93 KB/s
     2021-02-23     37.17 MB |   161.16 MB |   198.33 MB |      2.35 KB/s
     2021-02-24     46.78 MB |   190.85 MB |   237.64 MB |      2.82 KB/s
     2021-02-25     37.33 MB |   206.08 MB |   243.41 MB |      2.88 KB/s
     2021-02-26     37.58 MB |   179.62 MB |   217.20 MB |      2.57 KB/s
     2021-02-27     38.89 MB |   160.44 MB |   199.33 MB |      2.36 KB/s
     2021-02-28     84.04 MB |   173.76 MB |   257.80 MB |      3.05 KB/s
     ------------------------+-------------+-------------+---------------
      sum of 7     313.66 MB |     1.17 GB |     1.48 GB |
Ser4ph4 commented 3 years ago

Thanks for the answer, as the call on conky would look like, I currently use the one below:

${color}${font ConkySymbols:size=8}s${font}${color1}├─Network VnStat ${color}${goto 32} ├─Hoje ${goto 110} ─Ontem ${goto 180}─Semana ${goto 270}|─Mês ─|${color green}${font GE Inspira:size=10} ${execi 300 vnstat -i wlp0s29u1u3 | grep "today" | awk '{print $8" "substr ($9, 1, 1)}'} ${goto 113}${execi 300 vnstat -i wlp0s29u1u3 | grep "yesterday" | awk '{print $8" "substr ($9, 1, 1)}'} ${goto 10}${execi 300 vnstat -i wlp0s29u1u3 -w | grep "current week" | awk '{print $9" "substr ($10, 1, 1)}'} ${goto 315}${execi 300 vnstat -i wlp0s29u1u3 -m | grep "date +"%b '%y"" | awk '{print $9" "substr ($10, 1, 1)}'} ${color1}${goto 35}${stippled_hr}${color}

vergoh commented 3 years ago

I don't use Conky but looking at that output you appear to have the following information visible:

Most of those can be simplified somewhat to reduce the number of commands that get executed. Here's what you could do with vnStat 2.6:

vnstat -i wlp0s29u1u3 | grep "today" | awk '{print $8" "substr ($9, 1, 1)}' becomes vnstat -i wlp0s29u1u3 --oneline | cut -d\; -f4

vnstat -i wlp0s29u1u3 | grep "yesterday" | awk '{print $8" "substr ($9, 1, 1)}' will have to stay the same as --oneline doesn't have the previous day available and this may be intentionally such that is stays empty if the previous day wasn't monitored.

vnstat -i wlp0s29u1u3 -w | grep "current week" | awk '{print $9" "substr ($10, 1, 1)}' becomes vnstat -i wlp0s29u1u3 -d --begin $(date --date="next Monday -1 week" +"%Y-%m-%d") --end $(date +"%Y-%m-%d") | grep "sum of" | awk '{print $10 $11}' with the assumption that your weeks start on Mondays, use the backtick syntax for the date commands if Conky doesn't support the $(command) syntax

vnstat -i wlp0s29u1u3 -m | grep "date +"%b '%y"" | awk '{print $9" "substr ($10, 1, 1)}' becomes vnstat -i wlp0s29u1u3 --oneline | cut -d\; -f11

Hope this helps (and works).

Ser4ph4 commented 3 years ago

Thank you so much friend, for sure you helped me here =D