Let say, I have a web application that allows users to upload images and documents and my application stores all those assets on S3, is there a way I can monitor resource usage PER user account?
For example, if a user account has a 1GB storage limit, how can I monitor how much of that allowance any individual is using?
Furthermore (but this is less of an issue to me) if that user account also has a 5GB bandwidth limit, are there any tools available that allow me to monitor just their S3 bandwidth?
Yes, this is possible. You can use papreclip to manage file uploads (or any other reputable upload management plugin/gem). Most of these tools give you access to the filesize of the uploaded file. You can simply store these files in the database along with the asset_uri (which I imagine you’re already storing), and to check if a user can upload another file, simply sum all the sizes of all assets with the appropriate user_id.
Then, to grab the total size of uploaded files by a particular user, you could do:
You can see I’m making use of the ActiveRecord sum function here to do the calculation. You could just as easily use a map or some other ruby based solution.