Last Updated: February 25, 2016
·
503
· sakarikl

counting apache traffic from access logs

inspiration from:

http://stackoverflow.com/questions/8019742/measure-traffic-from-apache-access-log


#!/bin/bash

for arg in `find /var/log/httpd/ -maxdepth 3 -type f -name *access.log`
do
    echo ${arg}
    data=`cat ${arg} | perl -e 'my $sum=0; while(<>) { my ($traffic) = m/\[.+\] ".+" \d+ (\d+)/; $sum += $traffic}; printf("%.3f", $sum/1024/1024/1024)'`

    echo "$data GB"
    echo

done