Quick script to check user bandwidth usage

Sun, Apr 15, 2007 01:51 AM
A buddy needed a quick report to see if one of his users was slamming his site. I got a little carried away and wrote a PHP script (plus some awk and grep) to make a little report for him. I am sure it is full of bugs and will bring your server crashing down. So, use at your own risk.

$ ./bwreport.php -h
Usage: bwreport.php [-d YYYYMMDD] [-u URI] [-i HOST/IP] [-r REGEXP] [-v]
-d YYYYMMDD Date of the logs to parse. If no date provided, yesterday assumed.
-i IP/HOST Only report log lines with IP/HOST for host part of log line
-r REGEXP Only report log lines that match REGEXP. Should be a valid grep regexp
-u URI Only report log lines with URI match to URI
-v Verbose mode

http://www.phorum.org/downloads/bwreport.php.gz
2 comments
Gravatar for Tobias Struckmeier

Tobias Struckmeier Says:

I only looked briefly to your script, but because its a shell script, you should use $argv[0] instead of $_SERVER to access the script name.

Cheers

Gravatar for Tobias Struckmeier

Tobias Struckmeier Says:

Ah I forgot one tip.
Instead of the shebang
#!/usr/local/bin/php
this one is better
#!/usr/bin/env php
because it more independet from system environment :)

Comments are disabled for this post.