vergoh / vnstat

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

Wireguard interface disabled, can't enable #257

Closed kkettinger closed 10 months ago

kkettinger commented 10 months ago

I'm running vnstat 2.9 on ubuntu 22.04 inside proxmox. I'm trying to track usage of the wireguard interface wg0, but can't add/enable the interface.

$ vnstat
                      rx      /      tx      /     total    /   estimated
 br-47ff90b41a0b [disabled]:
       2023-11    779.67 MiB  /   42.98 GiB  /   43.74 GiB  /  110.21 GiB
     2023-11-12   779.67 MiB  /   42.98 GiB  /   43.74 GiB  /   48.30 GiB

 eth0:
       2023-11    667.95 GiB  /   32.07 GiB  /  700.01 GiB  /    1.41 TiB
     yesterday     32.97 GiB  /    1.41 GiB  /   34.38 GiB
         today     83.11 MiB  /  220.00 MiB  /  303.11 MiB  /  593.85 MiB

 veth68a2339 [disabled]:
       2023-11    967.88 MiB  /   42.98 GiB  /   43.92 GiB  /  110.67 GiB
     2023-11-12   967.88 MiB  /   42.98 GiB  /   43.92 GiB  /   48.50 GiB

 wg0 [disabled]:
       2023-11     43.88 GiB  /    1.29 GiB  /   45.17 GiB  /  113.81 GiB
     2023-11-12    43.88 GiB  /    1.29 GiB  /   45.17 GiB  /   49.88 GiB

Adding to database:

$ vnstat --add wg0
Error: Interface "wg0" already exists in the database.

Showing last data:

$ vnstat -5 wg0
No 5 minute data available.

Listing interfaces in database:

sqlite> select * from interface;
1|eth0||1|2023-11-12 20:16:57|2023-11-15 12:26:38|7995711200|789507930|717201638790|34431767028
3|wg0||0|2023-11-12 20:16:57|2023-11-12 21:44:00|0|0|47112124196|1385195196
4|br-47ff90b41a0b||0|2023-11-12 20:16:57|2023-11-12 21:44:40|0|0|817546968|46146300680
5|veth68a2339||0|2023-11-12 20:16:57|2023-11-12 21:44:40|0|0|1014897016|46146301030

No 5 minute data for interface wg0 (index 3):

sqlite> select interface, count(*) from fiveminute group by interface;
1|574

Reboot doesn't work. Any clue what is happening here? Why is there a "disabled" flag? Up on booting, the wg0 interface doesn't exist but is created after wg-quick up wg0. Restarting vnstat afterwards doesn't change the "disabled" flag.

vergoh commented 10 months ago

Which container image are you using? I'm guessing that if version 2.9 is in use then https://github.com/vergoh/vnstat-docker isn't the one being used?

"disabled" refers to the monitoring of that interface being disabled / not active. For versions 2.x that means that the daemon doesn't currently have visibility of the interface. You can verify the situation with vnstat --iflist which will list all currently available interfaces. It's likely that wg0 isn't on that list. Depending on how you've setup the container vnStat is running in a docker, it may be possible that the container doesn't have visibility for all the interfaces. For that to happen, you'll need to run the container having the vnStat daemon in it using host networking.

Depending on your needs, note that for Ubuntu 22.04 the latest vnStat release is also available via snap in addition to docker and the source package.

kkettinger commented 10 months ago

Thanks for your reply. Sorry, I meant proxmox instead of docker (it was late..), so it is a standard ubuntu 22 lxc container with the distribution default vnstat. Strangely, it seems to have fixed itself, now all interfaces are enabled.

If it happens again (maybe on a new lxc container) I will check the interfaces with --iflist.

vergoh commented 10 months ago

It's possible that if the Wireguard interface doesn't come up before the vnStat daemon gets started then the daemon will temporarily mark that interface as "disabled". However, the daemon does keep polling available interfaces and will detect if the wireguard interface is later activated. That's how you can get a situation where the interface is intially marked as "disabled" after boot and then re-enabled automatically later. Check the daemon log entries as all interface status changes get logged. See the configuration file for configuration options containing Interval for further details regarding the timings.