Extract bandwidth information from lighttpd log files

I was looking for a simple way to get some bandwidth statistics for websites that I host. Interested in historical data my only option was to look back over my webserver log files.

My webserver of choice on linux systems is currently lighttpd. Here’s a quick Bash script to get the bandwidth statistics out of the default lighttpd log files:

cat access.log | awk '{
year= substr($4,9,4)
timstamp=year" "month
bytes[timstamp] += $10
} END {
for (date in bytes)
printf("%s %20d MB\n", date, bytes[date]/(1024*1024))
}' | sort -k1n -k2M

That will give you a table containing the stats based on the bytes sent for the body of the pages:

2011 Jan                  662 MB
2011 Feb                12090 MB
2011 Mar                13645 MB
2011 Apr                12274 MB
2011 May                12279 MB
2011 Jun                 9551 MB

This could be easily adapted to work out the number of hits or other information contained in the log files.

Published by

Dave Hope

Dave works in IT for a leading UK based retirement developer, in his spare time he enjoys tinkering with technology and rock climbing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.