# Monitoring Disk Space Usage

**URL:** <https://www.ruby-forum.com/t/monitoring-disk-space-usage/76843>\
**Category:** Rails\
**Created:** [November 21, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/monitoring-disk-space-usage/76843 "2006-11-21T18:14:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 21, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/monitoring-disk-space-usage/76843/1 "2006-11-21T18:14:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 21, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/monitoring-disk-space-usage/76843/2 "2006-11-21T18:52:17Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [November 21, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/monitoring-disk-space-usage/76843/3 "2006-11-21T19:40:30Z")

</div>

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