Monitoring Disk Space Usage

Any recommendations out there for monitoring disk space usage for a
given user? Each time something is created or edited, compute the size
and and add it to a dedicated 'usage' field is my current plan. I don't
see anything built in that would address this.

Any recommendations out there for monitoring disk space usage for a
given user? Each time something is created or edited, compute the size
and and add it to a dedicated 'usage' field is my current plan. I don't
see anything built in that would address this.

I'm thinking your talking about disk space in the sense of your app lets users upload photos (or whatever) and you want to make sure they don't go over some set limit?

I can't think of anything built in to rails to do this, but you could certainly keep a counter in the database. If you do though, watch out for the case of a user uploading two files at nearly the same time and you holding onto the usage count for too long and it not being updated correctly. That is, in SQL terms you don't want this:

   UDPATE foo SET disk_space = #{disk_space} + #{some_size}

You want:

   UPDATE foo SET disk_space = disk_space + #{some_size}

So that if a lot of uploads for a single user come in very close together it will still have the right total.

You could also put each user's upload into their own directory and then use the OS command "du" to calculate the diskspace for that directory. I'd do this anyway so that nightly/weekly you could run this to bring the database upto a known point in case you do have any race conditions, etc.

-philip

Thanks for the info, wouldn't have thought of that!