I am tasked with figuring out the bandwidth used per directory on a parent directory in a linux server. We are hosting 10+ different client sites in 10+ different directories, and want to figure out the bandwidth per each on a single host.
I'd like to record the bandwidth used into a central area (text file, SQL database) so that I can then query the data for reporting later. I am comfortable writing the saving logic in PHP or bash.
I assume that we attach some sort of custom log file in our .conf
file, so that every time the page is loaded we determine the amount of assets (markup, images, etc) loaded for that single session and send that data to a database? I am trying to find someone much smarter than myself to determine how to best architect and roll this out so that we don't slow down the server and get the basic data needed.
The easiest way I can think of going about this would be to make use of your web server's logging mechanism to keep track of the bytes sent in response to each request.
For example, if you're using Apache, you can make use of
mod_log_config
to add aCustomLog
directive to create logs that look something like this:Once you have the data, you can write a simple script to calculate the bandwidth for each client based off the request URL.