qdm12 / gluetun

VPN client in a thin Docker container for multiple VPN providers, written in Go, and using OpenVPN or Wireguard, DNS over TLS, with a few proxy servers built-in.
https://hub.docker.com/r/qmcgaw/gluetun
MIT License
6.96k stars 339 forks source link

Feature request: vnstat like traffic monitor #251

Open coreshift opened 3 years ago

coreshift commented 3 years ago
  1. What's the feature? Ability to find out how much data has been sent/received through the vpn tunnel and keeping track of daily/monthly totals.

  2. Why do you need this feature? Limited data plans from ISP

  3. Extra information? Maybe there's already a way to find this out without adding a new feature?

qdm12 commented 3 years ago

I can add it. For now you could shell in the container and check iptables -nvL which would show how many bytes went through the firewall. But anyway, that's a good idea, I'll add it as an http endpoint on the http control server. One day I'll make a UI too which should help out monitor that. There is also #131 such that you could receive mobile notifications, I'll keep this in mind such that you can set warning limits.

coreshift commented 3 years ago

Thank you. Will the data persist across server reboots or container restarts? I'm sure it would make things more complicated if bw data has to be periodically stored to a data file or something. I tend to reboot or restart every few days.

qdm12 commented 3 years ago

Yes I can make it persistent to a file in /gluetun relatively easily, good idea too.

qdm12 commented 3 years ago

For my future self, ~/proc/net/dev seems to contain the data required. /proc/net/ip_vs_stats also contains current network rates.~ It might be interesting also to export these as prometheus metrics.

EDIT: Everything can be found using for example

link := netlink.LinkByIndex(9)
fmt.Printf("%#v\n", link.Attrs().Statistics)