vergoh / vnstat

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

wrong stat data for some interface #249

Closed alisalehiman closed 1 year ago

alisalehiman commented 1 year ago

Hello some vm interface for example tap100i0 interface name show incorrect stat data! today 8.00 EiB / 8.00 EiB / 16.00 EiB It is clear that this number cannot be correct, is this a bug? Thank you

vergoh commented 1 year ago

Hi, some more details would be needed, starting with the version that's being used, vnstat --version. Additionally, did this traffic occur "slowly" during the day or all at once? vnstat -h or vnstat -hg may show this, assuming it's executed within 24 hours of the event.

alisalehiman commented 1 year ago

Hi, vnStat 2.6 vnstat -h and vnstat -hg and vnstat -i has been attached. Thanks

Screen Shot 2023-05-30 at 20 51 07
alisalehiman commented 1 year ago

vnstat -i and vnstat -h

Screen Shot 2023-05-30 at 20 50 37
vergoh commented 1 year ago

It looks like some sanity check isn't getting correctly executed for that interface. Few more questions:

  1. Which OS / distribution is being used?
  2. What does vnstat --iflist output?
  3. What does vnstat --showconfig | grep -E 'BW|Band|Interval' output?
alisalehiman commented 1 year ago

1) Debian 11 - Kernel : 5.15.60 2) Available interfaces: tap10664i0 tap10665i0 tap7918i0 eno1 eno2 vmbr0 tap10526i0 tap7921i0 tap10531i0 tap10533i0 tap10535i0 tap10529i0 tap10572i0 tap10611i0 tap10646i0 tap10581i0 tap10585i0 tap7896i0 tap10567i0 tap10568i0 tap10569i0 tap10570i0 tap10573i0 tap10599i0 tap10576i0 tap10577i0 tap10580i0 tap10673i0 tap7938i0 tap10522i0 tap4043i0 tap10537i0 tap10586i0 tap10538i0 tap10587i0 tap10539i0 tap10540i0 tap10541i0 tap10542i0 tap10544i0 tap10545i0 tap10579i0 tap10546i0 tap10547i0 tap10764i0 tap4048i0 tap10548i0 tap10549i0 tap10550i0 tap4001i0 tap10601i0 tap10551i0 tap10602i0 tap10552i0 tap10603i0 tap10554i0 tap10605i0 tap8075i0 tap10553i0 tap7947i0 tap10557i0 tap10558i0 tap10575i0 tap10559i0 tap10607i0 tap10560i0 tap10608i0 tap10595i0 tap10562i0 tap10565i0 tap10653i0 tap10532i0 tap10517i0 tap10528i0 tap10592i0 tap10671i0 tap10594i0 tap10514i0 tap10598i0 tap10516i0 tap10635i0 tap10574i0 tap10556i0 tap10561i0 tap10563i0 tap10564i0 tap10612i0 tap10524i0 tap10457i0 tap10613i0 tap5898i0 tap10616i0 tap10618i0 tap10527i0 tap10610i0 tap10628i0 tap10566i0 tap10520i0 tap10521i0 tap10773i0 tap10455i0 tap10454i0 tap10615i0 tap10633i0 tap10650i0 tap10530i0 tap10617i0 tap10543i0 tap5912i0 tap7934i0 tap7951i0 tap5895i0 tap10626i0 tap10589i0 tap4034i0 tap10578i0 tap4063i0 tap8067i0 tap10642i0 tap5907i0 tap10637i0 tap8008i0 tap8046i0 tap10593i0 tap7950i0 tap10591i0 tap10596i0 tap5913i0 tap5914i0 tap7930i0 tap5922i0 tap10536i0 tap5931i0 tap10604i0 tap10525i0 tap10534i0 tap8039i0 tap8018i0 tap10662i0 tap10584i0 tap10590i0 tap10582i0 tap10583i0 tap10614i0 tap10571i0 tap10656i0 tap10622i0 tap8058i0 tap10519i0 tap10518i0 tap10515i0 tap10523i0 tap10600i0 tap7917i0

3) vnstat --showconfig | grep -E 'BW|Band|Interval'

MaxBandwidth will be used as fallback value when enabled

BandwidthDetection 0 MaxBandwidth 10000

MaxBWeth0 8

;UpdateInterval 20 ;PollInterval 5 ;SaveInterval 5 ;OfflineSaveInterval 30

BandwidthDetection is enabled (0 = disabled)

;BandwidthDetectionInterval 5

alisalehiman commented 1 year ago

@vergoh any idea?

vergoh commented 1 year ago

Looking at your traffic rates outside the invalid data, there's nothing even close to the set 10 Gbit MaxBandwidth which should have otherwise acted as a sanity check. Any reason for this configuration and BandwidthDetection being set to 0?

Currently I don't have any clue why that invalid data ends up being exactly 8.00 EiB for both rx and tx. Those aren't the upper limits of 32-bit or 64-bit integers and both being exactly the same would suggest all other traffic got somehow ignored during that hour. The five minute resolution output would be interesting to see for that time range if it still exists.

alisalehiman commented 1 year ago

I guess this problem occurred after I set these two variables to zero.(MaxBandwidth and BandwidthDetection) Before that, this problem did not exist, but the traffic was calculated much less than the actual value. vnstatd[3823685]: Info: Traffic rate for "tap10093i0" higher than set maximum 10 Mbit can you help me how to fix this error without problem?

vergoh commented 1 year ago

If you know what those interfaces are and what the maximum throughput is then set that value to MaxBandwidth. If you don't then set MaxBandwidth to 100 which is likely to be right enough based on what's visible in those screenshots. If you still get that info message then use 1000 instead.

I'm not really sure from where that 10 Mbit came from anyway since it's not the default value in vnStat. It's also possible there's a similar hardcoding existing for "tap" interfaces which was noticed for "tun" interfaces in the Linux kernel and was bypassed in vnStat 2.8. I'll have to check that.

alisalehiman commented 1 year ago

Thank you

Pigpog commented 1 year ago

Hello, I am also having this issue. I am trying to use vnstat to meter cellular data usage on my PinePhone Pro (running Arch Linux ARM). I have a 1 gigabyte data cap, and initially vnstat was accurately measuring the data used. After a day or two, it started showing tens of gigabytes of data used for no apparent reason. I completely reset the database in the hopes that it was a fluke, but the issue cropped up again. I have been very sparing with my data usage this month.

You can see in the below snippet that June 1 reports 12 GiB for both Rx and Tx. Similarly, June 11 shows 4 GiB for both.

[alarm@danctnix ~]$ vnstat -d -i wwu1i4

 wwu1i4  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2023-06-01    12.01 GiB |   12.00 GiB |   24.01 GiB |    2.39 Mbit/s
     2023-06-02     9.44 MiB |  829.75 KiB |   10.25 MiB |      994 bit/s
     2023-06-03          0 B |         0 B |         0 B |        0 bit/s
     2023-06-04     2.74 KiB |    1.91 KiB |    4.65 KiB |        0 bit/s
     2023-06-05          0 B |         0 B |         0 B |        0 bit/s
     2023-06-06          0 B |         0 B |         0 B |        0 bit/s
     2023-06-07          0 B |         0 B |         0 B |        0 bit/s
     2023-06-08          0 B |         0 B |         0 B |        0 bit/s
     2023-06-09     1.14 MiB |  615.23 KiB |    1.74 MiB |      168 bit/s
     2023-06-10     4.21 MiB |  857.99 KiB |    5.04 MiB |      489 bit/s
     2023-06-11     4.00 GiB |    4.00 GiB |    8.01 GiB |  796.05 kbit/s
     2023-06-12          0 B |         0 B |         0 B |        0 bit/s
     ------------------------+-------------+-------------+---------------
[alarm@danctnix ~]$ vnstat --showconfig | grep -E 'BW|Band|Interval'
# MaxBandwidth will be used as fallback value when enabled
;BandwidthDetection 1
;MaxBandwidth 1000
#MaxBWeth0 8
;UpdateInterval 20
;PollInterval 5
;SaveInterval 5
;OfflineSaveInterval 30
# BandwidthDetection is enabled (0 = disabled)
;BandwidthDetectionInterval 5
[alarm@danctnix ~]$ vnstat --iflist
Available interfaces: wlan0 wwu1i4

Looking at my wlan0 interface, it also shows these "symmetrical" increases:

[alarm@danctnix ~]$ vnstat -d -i wlan0

 wlan0  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2023-05-31    35.12 MiB |   44.67 MiB |   79.79 MiB |    7.75 kbit/s
     2023-06-01   239.54 MiB |   10.02 MiB |  249.55 MiB |   24.23 kbit/s
     2023-06-02    35.61 MiB |    9.69 MiB |   45.29 MiB |    4.40 kbit/s
     2023-06-03     2.70 MiB |    1.62 MiB |    4.31 MiB |      418 bit/s
     2023-06-04     8.03 GiB |    8.01 GiB |   16.03 GiB |    1.59 Mbit/s
     2023-06-05   264.18 MiB |   15.11 MiB |  279.29 MiB |   27.12 kbit/s
     2023-06-06     9.00 MiB |  578.78 KiB |    9.57 MiB |      928 bit/s
     2023-06-07    40.66 MiB |    5.61 MiB |   46.27 MiB |    4.49 kbit/s
     2023-06-08     4.05 GiB |    4.00 GiB |    8.05 GiB |  800.53 kbit/s
     2023-06-09     8.54 MiB |  796.38 KiB |    9.32 MiB |      904 bit/s
     2023-06-10    33.45 MiB |   14.71 MiB |   48.16 MiB |    4.67 kbit/s
     2023-06-11     8.02 GiB |    8.00 GiB |   16.03 GiB |    1.59 Mbit/s
     2023-06-12    43.13 MiB |   74.35 MiB |  117.48 MiB |   14.66 kbit/s
     ------------------------+-------------+-------------+---------------

I will continue tinkering, feel free to ask me to try things to help troubleshoot.

alisalehiman commented 1 year ago

@Pigpog Please set MaxBandwitdh 1000 on /etc/vnstat.conf and restart vnstat service

Pigpog commented 1 year ago

Thanks, I have changed that value now, and manually corrected the usage data in the sqlite database. Hopefully it stays accurate this time.

alisalehiman commented 1 year ago

you can remove and add incorrect interface.

Pigpog commented 1 year ago

I'm still having this issue after changing the setting. Even if that did work, I don't think this issue should be closed if the out-of-box behaviour completely undermines the purpose of this software.

The program adds exactly 4 GiB of usage on both Rx and Tx at seemingly random times (every couple days maybe). The only factors i think would be relevant are that the interface goes up and down multiple times an hour as i toggle cellular, spends most of its time disabled, and the device suspends to RAM often.

I'd appreciate some pointers for debugging this issue, as i'm motivated enough to PR a fix for this.

Edit: This issue also happens on my WiFi interface. The 4 GiB is added at differing times from the cellular iface, though with similar frequency.

vergoh commented 1 year ago

@Pigpog - please open a new issue if the problem persists or if you want to discuss this in more details. Based on the details you've given, the issue you are having isn't the same as the author of this issue described. Sadly GitHub doesn't appear to allow me to split your messages to a new issue.

Note that if the interface can't (or doesn't normally) have a throughput of 1000 Mbit then having MaxBandwitdh 1000 in the configuration file isn't the correct solution.

Pigpog commented 1 year ago

well whaddya know, i set maxbandwidth to 100 and i havent had the issue since. thanks!