Using ColdFusion to check available disk space

This post is more than 2 years old.

I mentioned this in a presentation last week but I thought I'd bring it up with a concrete example. For those of you who allow file uploads to your server, how many of you actively check your free space on your server? Even if you don't use that feature, do you monitor free space anyway? Log files, in particular, can suck up quite a bit of space. Here is an incredibly simple ColdFusion template that checks for a minimum number of gigs of free hard drive space. If it is less than that threshold, or at 0, which didn't happen to me yesterday, honest, then it fires off an email.

Set this up to run hourly and you should be good to go. You could also make this check multiple drives if your server makes use of them.

So yeah -this so didn't bite me in the ass. Honest.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Seth Johnson posted on 1/22/2013 at 8:50 PM

Thanks a bunch for this post Ray, will come in really handy for monitoring AWS space usage. I tried it and it worked on Railo right out of the box too.

Comment 2 by Raymond Camden posted on 1/22/2013 at 8:58 PM

AWS brings up a good point. I was going to mention that even if used AWS for file uploads, you may still get screwed by log files (that's what screwed me), but your example is great too. This could be used to ensure your AWS store doesn't go super high and cost you a bundle.

Comment 3 by Tarek Ezzeddine posted on 1/22/2013 at 9:16 PM

nice post, But how to apply the same in CF9? any way?

Comment 4 by Raymond Camden posted on 1/22/2013 at 9:21 PM
Comment 5 by GrumpyCFer posted on 1/23/2013 at 5:13 AM

Note that with standard configurations at extremely low disk space, the email will not be sent because it can not be spooled to disk.

There are ways around that, like spooling to memory, but it's something to be aware of.

Comment 6 by Raymond Camden posted on 1/23/2013 at 6:35 AM

Hence the minimum of 1 gig above. ;)

Comment 7 by GrumpyCFer posted on 1/23/2013 at 12:36 PM

We once had a rogue process on a crash/restart loop. The logs chewed up more than a few gig in the space of an hour. Just something to be aware of...

Comment 8 by alecken posted on 10/14/2016 at 3:02 PM

I don't see where is the function for getFreeSpace('./')

Comment 9 (In reply to #8) by Raymond Camden posted on 10/14/2016 at 3:04 PM

It is a ColdFusion function. I'm not sure when it was added, but certainly over 3 years ago.