Quick script to check user bandwidth usage

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

Advertisements

2 Responses to Quick script to check user bandwidth usage

  1. 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

  2. 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 :)

%d bloggers like this: