monitor-bandwidth-usage

How to monitor all Virtual Host Bandwidth usage in Apache using access log

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

YOU MAY ALSO LIKE...

RELATED POSTS...

How to fix apache ssl_module skipping warning if a... Recently I faced another issue during Apache restart. When I ran “httpd -t” command to check Apache configuration. I got ” module ssl_module is alre...
Finding causes of heavy usage on web server using ... Sometimes you noticed your server loading slowly or down and sometimes you also noticed that your servers resources usage are more at particular time ...
Install Latest Apache 2.4, MySQL 5.6, And PHP 5.6 ... Apache is a web server that runs on most Linux/UNIX based operating system as well as on Windows. It is free and open source HTTP web server. It is us...
Easy Steps To Configure Browser Caching (Leverage ... OVERVIEW :Caching is the temporary storage of content like image,file,bits of php scripts,html page, css and other web objects.It store data in ...
How to Enable Worker MPM in Apache 2.4 Apache Multi-Processing Modules (MPM) used for creating child processes in Apache. Apache Worker MPM is able to server large number of requests with f...
How to Secure Apache Web Server On Linux/UNIX Apache HTTP server is the world's most famous and used web server to host your web files or your websites on the web. Every Linux administrator should...

Sagar

Hi! I'm Sagar and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Reply

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