If you are trying to find a way to monitor the bandwidth usage of virtual host in Apache without installing something like PLESK, CPanel, Or ISPConfig. This article will help you to find the each virtual host bandwidth usage. This is the READ-ONLY solutions because no need to install any extra package on your system. Just you will need to enable Apache access log.
In my example there is actually multiple vhosts on the server and therefore multiple site.com.access_log’s file is stored on /var/log/httpd/vhost/ location.
# cd /var/log/httpd/vhost/ # ls -l total 93180 -rw-r--r-- 1 nginx root 3858856 Mar 19 15:43 dev.looklinix.com_access.log -rw-r--r-- 1 nginx root 83182328 Mar 19 15:53 looklinix.com_access.log -rw-r--r-- 1 nginx root 647082 Mar 10 13:12 blog.looklinix.com_access.log -rw-r--r-- 1 nginx root 7531591 Mar 19 14:41 stats.looklinix.com_access.log
Bandwidth Usage of Single Virtual Host in MB
Follow the below command to find the single Virtual Host bandwidth usage in MB.
# cat looklinix.com_access.log | awk '{SUM+=$10}END{print SUM/1024/1024}'
3599.35
Bandwidth Usage of all Virtual Host in MB
Follow the below command to find the all Virtual Host bandwidth usage in MB.
# for f in *access.log ; do echo `awk '{SUM+=$10}END{print SUM/1024/1024}' $f` $f ; done | sort -rn | more 3599.25 looklinix.com_access.log 559.961 stats.looklinix.com_access.log 445.563 dev.looklinix.com_access.log 30.1865 blog.looklinix.com_access.log
If your logs are rotating and stores in gzip format you can follow the below command to monitor bandwidth usage.
Bandwidth Usage of Single Virtual Host in MB
# for f in looklinix.com_access.log.1.gz ; do echo `zcat $f|awk '{SUM+=$9}END{print SUM/1024/1024}'` $f `stat -c%z $f`; done | sort -rn | more
3599.35 looklinix.com_access.log.1.gz 2017-19-03 01:01:15.000000000 -0600
Bandwidth Usage of all Virtual Host in MB
# for f in *access.log.*.gz ; do echo `zcat $f|awk '{SUM+=$10}END{print SUM/1024/1024}'` $f `stat -c%z $f`; done | sort -rn | more 3489.27 looklinix.com_access.log.1.gz 2017-19-03 04:02:09.591534622 -0600 546.96 stats.looklinix.com_access.log.3.gz 2017-19-03 04:02:08.320527382 -0600 435.53 dev.looklinix.com_access.log.4.gz 2017-19-03 04:02:08.320527382 -0600 31.1265 blog.looklinix.com_access.log.2.gz 2017-19-03 04:02:08.320527382 -0600
If you want to monitor bandwidth usage in GUI mode don’t miss my previous article.
I hope this article will help to monitor your all Virtual Host Bandwidth usage. If having any issues or questions, please feel free to mention them in the comment box below.
Thanks
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment