vergoh / vnstat

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

SaveInterval Unit #263

Open wy2919 opened 2 months ago

wy2919 commented 2 months ago

Hello! Very cool application

It would be great if the unit of SaveInterval could be set to seconds, changing the unit would not affect the usage and would give the user more options and flexibility.

I read your answer in this thread, I think 4 years have passed, most of the servers are SSD now, IO should not be a big problem, could you consider changing the SaveInterval unit?

https://github.com/vergoh/vnstat/issues/157

vergoh commented 2 months ago

The question from #157 is still applicable: What is the practical scenario for which you'd want to have the database written more often than the current limit of once every minute?

Changing the unit of an existing configuration isn't something I'm eager on doing. It would have the implication of breaking any possibly already existing post-configuration scripts which are setting SaveInterval so some specific value as that value wouldn't anymore have the desired effect. There are also for example plenty of embedded devices using vnStat where having a frequent disk write interval isn't practical due to how slow the media is or due to the wear writes can cause on the media. If there's nobody looking at the stats that often then it usually doesn't matter that much if the data is 1, 5 or 15 minutes old.

wy2919 commented 2 months ago

I want to write a server traffic control program, because some servers have traffic restrictions, so I need to control my server traffic, use your open source vnstat program to get the server's current month's upload traffic, because the server export bandwidth is very large, so the measurement should be more accurate, so you need to vnstat shorter intervals!

If it is a compatibility issue, you see if you can add a new field for the unit of SaveInterval, the new field is just the unit of SaveInterval, the unit of the newly added field is minutes by default, but can be changed to seconds, so that you can be compatible with the old configuration file, but also provides additional extensions!

Of course, this is just a suggestion.

vergoh commented 2 months ago

I'm not sure if I fully understand the situation. The minimum value for SaveInterval is currently 1 so vnStat would update the database every minute. If you are targetting to stop the traffic on some server before the monthly transfer cap is reached, it should be enough to leave one minute worth of maximum transfer as "safety margin" when doing the evaluation of amount used so far (something you could use --alert for).

Is your configuration such that the server's transfer cap is so small and the maximum bandwidth so high that having a one minute "safety margin" would be too much? That would sound rather unusual but if that's the case, could you provide the actual numbers if possible?

If for example something like SaveIntervalSeconds would be implemented, the lower bound of the configuration would still be limited by UpdateInterval and PollInterval since there's no point saving the data more often than the data is getting read. That would most likely make writing the data possibly every 5-10 seconds as a lower limit if really necessary. I suspect the sqlite parameters could use some changing if such configuration is used in order to limit the disk write/sync penalty possibly caused by such frequent database writes (as in, I have no idea how much there would be a performance impact, if any, when using SSDs and the current default sqlite parameters).