vergoh / vnstat

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

Can vnstat load traffic data that passed through eth0 before it was installed? #223

Closed uidterry closed 2 years ago

uidterry commented 2 years ago

If traffic data was already generated , before vnstat was installed and can be read by 'cat /proc/net/dev' and 'nload'. Will vnstat be able to load the history of the eth0 network interface?

vergoh commented 2 years ago

vnStat uses only /proc/net/dev or /sys/class/net as source depending on availability. Both of these sources provide only "right now" type of information without any historical data. As a result, when vnStat is installed to a system for the first time (or the database doesn't exist during startup), it will assume that what those sources contain is the starting point, the zero, for the database and the interfaces. The only case when history data can be imported is when you upgrade from one version of vnStat to another.

uidterry commented 2 years ago

so , Can vnstat load the data if it's already in /proc/net/dev, rather than starting from the zero?

vergoh commented 2 years ago

/proc/net/dev shows how much traffic has accumulated after the latest system startup (but doesn't tell you when) assuming the kernel and interface drivers are using 64-bit integers. Otherwise the data would have a rollover at 4GB so it wouldn't even be possible to know the real number. As months may have passed since the last system reboot, it's impossible for vnStat to place that data over the correct period. In addition, if the numbers are below 4GB then it's also rather difficult to guess if there will be (or has been) a rollover at 4GB. That's why vnStat doesn't try guess if the traffic that's visible there happen during the last 5 minutes or over several months and instead starts from zero.

If you have some idea for an alternative behaviour then I can of course consider adding it as an alternative mode of operations, assuming the logic is sound, not too complicated and can be explained with concrete examples.

There's also the alternative of just editing the database directly and adding traffic there based on some other information source you have. vnStat isn't going to help you with such import but if you stick with the existing sqlite database structure and format then it will not reject the data either.