How one could monitor and keep logs of daily, weekly and monthly bandwidth usage of Linux servers? This is important for cheap VPS solutions where they have monthly caps in bandwidth.
Preferable some lightweight command-line tool just for this purpose.
Even more preferably nothing which includes PHP or web code.
It's enough to count all inbound / outbound traffic per network interface. This is just for one VPS, nothing heavy weight needed.
Utilize a network/resource monitoring solution like Observium or Munin or Cacti... That will provide graphical historical and summary information about your traffic patterns. Run it directly on the server.
For a command line option, collectl is nice.
sar (from the sysstat package) would probably be your best bet. You may need to backup the logs and probably draw up a couple of quick scripts to generate the type of statistics you want but it shouldn't be too hard.
Once installed a cron runs every ten minutes and saves stats out to a file (on Red Hat, this is stored in
/var/log/sa/sa<day of month>
). As well as network activity it also keeps track of CPU and IO stats.It isn't as feature rich as some of the other tools people have mentioned but should suit your purpose.
The homepage is here: http://sebastien.godard.pagesperso-orange.fr/
MRTG is a good lightweight option. It takes a little while to figure out the configuration file but once it's setup it'll run for years. A lot of ISPs use this to monitor their network interfaces. How do you plan to monitor their usage? By IP address going through a router, by switch port or something else?