vergoh / vnstat

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

Configure start of graphs #216

Closed Ep0chalypse closed 2 years ago

Ep0chalypse commented 2 years ago

I would like to be able to configure the hourly graph to start at midnight. Currently the graph starts when the daemon is started. For example these two images have the starting time be 19 https://i.imgur.com/0LUSHT1.png https://i.imgur.com/1EDIoqf.png

Ideally when vnstati is run with the -hg option, vnstati would figure out the current date and generate the graph from 00(midnight) of that day to 23:59(11:59pm) of that night. Or add a command line switch like -hg-start and -hg-end to accept a value of 0-23.

vergoh commented 2 years ago

The output of the hourly graph is currently fixed to be the last 24 hours. It's not tied to the daemon startup time in any way and will fill any hours without data with zeros if the daemon hasn't been running constantly during the last 24 hours.

Do I understand your request correctly that you'd want to have an option that would configure the hourly graph to always show the "current day" starting from midnight and show possibly future hours filled with zeros instead of the currently implemented sliding window?

-hg doesn't take currently any parameters so having an optional parameter for behaviour configuration could be one possibility. However I'm not sure how exactly you'd want the graph to behave when you say that that start and end should be configurable with values 0-23 as the output size is still limited to 24 hours and doesn't support scaling it longer or shorter.

-hg doesn't either use the --begin and --end parameters but probably it's better not to mix those two in as long as the graph is limited to 24 hours.

vergoh commented 2 years ago

I did some quick prototyping and getting from image to image didn't require too many changes. Most likely writing the configurability and documentation would be more work than the feature itself, assuming a toggle for "start hourly from 00" is what you were looking for.

Ep0chalypse commented 2 years ago

Do I understand your request correctly that you'd want to have an option that would configure the hourly graph to always show the "current day" starting from midnight and show possibly future hours filled with zeros instead of the currently implemented sliding window?

Yup. I find it easier to look at the graph and process the times.

Most likely writing the configurability and documentation would be more work than the feature itself, assuming a toggle for "start hourly from 00" is what you were looking for.

That would be a great addition. Hopefully this isn't too much work

vergoh commented 2 years ago

Just wanted to make sure I got the specification right before I implement so that the feature doesn't end up being a misunderstanding and nobody then uses it. The hourly graph also appears to be missing the vertical line for midnight for some reason that's in the 5 minute graph so I'll add that too (assuming it fits with the style).

vergoh commented 2 years ago

The new configuration file option for this feature is HourlyGraphMode ( https://github.com/vergoh/vnstat/blob/master/cfg/vnstat.conf#L191 ) and both -hg and --hoursgraph accept an additional optional parameter from the command line if the configuration file needs to be overridden for some reason. db25864 on the master branch doesn't have that many changes compared to the released version 2.8 if you'd want to take this into use right away instead of waiting for the next release.