I've just deployed a Codeigniter application to Amazon EC2 (using S3 for media and RDS for MySQL).
I need to restrict user account access based on the amount of bandwidth used - accounts will be based on bandwidth e.g. Basic account £x for up to 20GB per month etc.
However I've no idea what the best way to do this is.
My EC2 instances are Ubuntu with Apache2 if that helps.
Any ideas appreciated!
Thanks!
You can use the amazon's API to check the bandwidth usage , instead of using the logs .
as you have said that you are using s3 for managing the assets , it will be good if you create a new bucket for every user and check the bandwidth usage and then limit the account if he/she exceeds that limit.
Limiting bandwidth per each connection for linux pc
You have to install "Lighttpd" tool, its an web server. it is useful to limiting the bandwidth per connection and I also install Axel for increase and decrease the number of connections.
sudo apt-get install axel
http://www.cyberciti.biz/tips/installing-and-configuring-lighttpd-webserver-howto.html
per connection i add this command in this path /etc/lighttpd /lighttpd.conf.
connection.k bytes-per-second=70
I limit the bandwidth for 70 kb/sec and I tested each connections for 5 times and i observed minimum time, maximum time and I calculated average time. I repeated this up to 10 connections.
You can create custom log with Apache to track the number of bytes transferred. The difficult part will be associating that to a given user. Probably a combination of cookie and maybe remote IP.
You would then take that log and process it in the background.
S3/Cloudfront can provide similar logs, but you probably wont be able to associate it to a user.
If you use output buffering in PHP, you can call ob_get_length()
just before calling ob_end_flush()
to get the size of the output buffer that you are sending to the client.
If you also implement a PHP handler for all files (rather than allowing for direct links to the files via Apache), you'd have a pretty decent idea of exactly how much content you were sending each client.