vergoh / vnstat

vnStat - a network traffic monitor for Linux and BSD

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pause data logging when stopping the service

GuerreroNinja opened this issue · comments

Hi, thank you for the great tool that is vnstat. Sorry if this is a stupid question...

I want to monitor my mobile data traffic in order to manage my monthly bandwith. I made a script using Kargos to show the bandwith consumed in taskbar. However, I also use a DLNA server to watch movies, and, unfortunately, that traffic gets registered. I switch WiFi networks in order to do so, but still vnstat can't log by SSID, all goes to the interface.

So, the "fix" I apply is a script to change and stop vnstat service when I watch movies from my VR glasses, like this:

nmcli c down MOBILEDATA
systemctl stop vnstat.service
nmcli c up HOTSPOT

However, when I start the service again, the vnstat database updates with the bandwith consumed when watching the movie.

Any idea to "pause" the database update?

Locate that vnstat.service file and edit it. It should contain something like ExecStart=/usr/sbin/vnstatd -n in the [Service] section. Add --sync at the end of that line. The end result should look something like ExecStart=/usr/sbin/vnstatd -n --sync. Save the file and execute systemctl daemon-reload for systemd to notice that change. After that change, any systemctl start vnstat.service will cause the daemon to ignore any traffic that was after the previous stop.

Documentation about --sync from the man page:

       -s, --sync
              Synchronize  internal  counters  in  the database with interface
              counters for all available interfaces  before  starting  traffic
              monitoring.  Use this option if the traffic between the previous
              shutdown and the current startup  of  the  daemon  needs  to  be
              ignored.  This  option  isn't required in normal use because the
              daemon will  automatically  synchronize  the  internal  counters
              after  a system reboot, if enough time has passed since the dae‐
              mon was previously running  or  if  the  internal  counters  are
              clearly out of sync.

Superb! That was what I needed, I really did not understand it fully when I read the manpage. Thank you!