vergoh / vnstat

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

Wifi hotspot name (ssid) awareness #128

Open artumi-richard opened 5 years ago

artumi-richard commented 5 years ago

Hi

Thanks for your work on vnstat. I'm using it to determine the correct level of internet provision I should buy and it would be helpful if I had a breakdown of my wifi interface by the network it was connected to, ideally using the wifi hotspot name. Since I don't know how much of the data going through the wifi interface is going through my phone's hot spot, and how much is going through my home internet, and how much is going through my work's internet, it's hard for me to make a good decision about changing what access I need.

Thanks again.

vergoh commented 5 years ago

That's an interesting idea and it might even be possible to implement with the new database model. Quickly thinking, this would at least require adding support for some sort of pseudo interfaces that get stored in the database but aren't directly tracked and making vnStat able to detect which interfaces are wireless and getting somehow the essid information. That could then allow storing the traffic information twice, once for the interface itself and a second time for the pseudo interface named something like _.

I suspect getting the essid information is likely to differ between Linux and BSD requiring therefore different implementations for each. Which distribution do you have in use?

artumi-richard commented 5 years ago

I'm using Linux (Ubuntu LTS).

vergoh commented 5 years ago

Short update:

It looks like there's no /proc or /sys interface available for getting the ssid string. /proc/net/wireless is the closest and is available if the kernel has wireless interface support included. While that interface provides details about the link status and quality, it lacks th ssid string for some reason. The remaining options appear to be either using libiw or ioctl call for SIOCGIWESSID.

Another matter that came to mind is that the ssid can contain all sorts of characters and most likely also some non-ASCII ones. Trying to type something like vnstat -d -i "wlan0_鱼汤" might not be that practical depending on the used keyboard so some other way of accessing the ssid created pseudo interfaces would be needed.

artumi-richard commented 5 years ago

Update appreciated. iwgetid --raw (system command - part of wireless-tools) will produce the ssid string. It's source code is here https://github.com/HewlettPackard/wireless-tools/blob/master/wireless_tools/iwgetid.c if you want to pull out the bit you need to avoid a dependency.

vergoh commented 5 years ago

That example directly adds a dependency to libiw (and its development package) and that's something I'd prefer to avoid. https://gist.github.com/lf-/90912626f24246540e52 does pretty much what I need after few minor modifications. Haven't yet searched what the equivalent for BSD is.