Important alert: (current site time 7/15/2013 8:44:45 PM EDT)
 

VB icon

Bandwidth Monitor

Email
Submitted on: 6/12/2004 2:34:41 PM
By: Damian myerscough  
Level: Intermediate
User Rating: By 1 Users
Compatibility: 5.0 (all versions), Active Perl specific, 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 11076
 
     I seen this feature in cpanel and I always wanted to create this so here it is Apache bandwidth user monitor
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Bandwidth Monitor
= Description:I seen this feature in cpanel and I always wanted to create this so here it is Apache bandwidth user monitor
= By: Damian myerscough
=
= Returns:Amount of bandwidth used by a user
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=592&lngWId=6=for details.=**************************************

#!/usr/bin/perl -w
#
#
open(LOGFILE, "/var/log/apache/www.planet-source-code.com-access_log") || die "Could not open file $!\n";
	@Bandwidth = <LOGFILE>;
close(LOGFILE);
$i = 0;
foreach $Band (@Bandwidth)
{
	@seperate = split(/ /, $Band);
	$ustage[$i] = $seperate[9]; 
	$i++;
}
$i = 0;
foreach $value (@ustage)
{
	$i++;
		if($value =~ m/\d/)
		{
			$Total = ($value + $Total);
		}
}
##################################
# Convert The Bytes to megabytes #
##################################
$Total = ($Total / 1024);
$Total = ($Total / 1024);
print"Total Numbers: $Total" . "MB\n";


Other 35 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/16/2004 11:35:50 AMcianid3

code dosen't work. It prints the folowing on my unix server
Total numbers: 0MB

(If this comment was disrespectful, please report it.)

 
9/16/2004 4:11:05 PMDamian myerscough

This code does work!

I have tested it on my **apache** server I have not tested it on any other server.

The log file format that I used it one was setup like:


82.96.96.3 - - [16/Sep/2004:19:50:15 +0100] "POST http://82.96.96.3:802/ HTTP/1.0" 405 305
(If this comment was disrespectful, please report it.)

 
9/16/2004 4:13:07 PMDamian myerscough

heres the example:

Total Numbers: 0.00982666015625MB
(If this comment was disrespectful, please report it.)

 
3/25/2005 3:22:07 AM

sir,
i donot know how to work this pgm,could u give a brief insight into this please
(If this comment was disrespectful, please report it.)

 
3/25/2005 8:26:53 AMDamian myerscough

Hi,

The way this script works is by opening the users apache access_log on your machine.

So you would have to change the following open file to:

open(LOGFILE, "/path/to/apaches/access_log") || die "Could not open file $!\n";

Change the path to where your apaches access_log is.

I have tested this script on my Fedora Core 3 machine so this script also works with Apache v2.

if you need any more help just email
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.