Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Background: I'm a developer who reluctantly "looks after" the machine onto which my application is deployed. My customer is an entirely separate company who pay us to write code for them - we have no bosses in common or anything like that. They have sysadmins but they are in a different department and when they ask for the sorts of things I think sysadmins should be able to do for them, they don't get what they asked for. Making that happen is out of my hands. I then end up being asked to write code to do things that I suspect an actual trained person could set up with a few lines of powershell or by ticking something on a dialog. This is a Windows Server 2003 setup with SQL and IIS installed.

Which leads to today's problem: how to know the drives are getting full. (Database growth, exported files not cleaned up, that sort of thing.) Ideally an email would go out saying "Drive E is at abc of xyz (84%)." Is that easy to do? I sure don't want to write a service to monitor disk space and send emails - someone must have done this before. One of the drives is actually a mapped drive representing a folder on another machine for what that's worth.

share|improve this question
add comment

7 Answers

up vote 2 down vote accepted

While many of the answers include scripting (and if you go that route I'd also suggest powershell) you can also perform alerting using perfmon. See HOW TO: Configure a Low Disk Space Alert by Using the Performance Logs and Alerts Feature in Windows Server 2003

Note that the action you want to take would be to execute a powershell or vbscript to send you an email (or perhaps more preferable, perform some basic cleanup tasks on the drive, then send an email stating what the problem was and what the post action number is)

For the mapped drive you have to use a script. In the WMI counter to use is win32_mappedlogicaldisk. (Get-WmiObject win32_mappedlogicaldisk).freespace. EG:

$mythreshold = 10GB
Get-WmiObject win32_mappedlogicaldisk | select-object deviceid, freespace | foreach { 
    if ($_.freespace -lt $mythreshold){

        $from = "myaddr@mycompany.com" 
        $to = "myaddr@mycompany.com" 
        $subject = "Low Disk Space!" 
        $body = "Free Space Remaining: " + $_.FreeSpace + "Drive" + $_.deviceid 
        $smtpServer = "smtp.mycompany.com" 
        $smtp = new-object Net.Mail.SmtpClient($smtpServer) 
        $smtp.Send($from,$to,$subject,$body) 
    } 
    }

(much of the prior code cheerfully copied from squillman as otherwise I would have had to type in this code myself)

share|improve this answer
add comment

If you're running Server 2003 R2, you have access to the File Server Resource Management tool. This allows creating directory quotas that have notifications attached. You'd be interested in the soft quotas where it doesn't stop new data from being added. You can add notifications to alert you when pre-set threshold are crossed.

If you're on Server 2003 without R2, then you're into the land of external monitoring tools or scripts.

share|improve this answer
    
Sigh. That sounds perfect, but getting it moved to R2 seems like it would meet with the same success as the other requests. –  Kate Gregory Sep 2 '10 at 19:59
add comment

This might work for you. If you create a script (Powershell would be my recommendation) that checks the free disk space at run-time and fires off an email if it falls below your threshold, you could create a scheduled task on the server that runs that script. Schedule it for every X minutes and you've got yourself a poor-man's monitoring solution. It is admittedly more prone to errors than other solutions like Nagios or R2's resource manager, but hey...

Your Powershell script could look something like this:

$freeSpaceThreshold = 5GB
$computerName = "mycomputer"
$drive = "C:"

$driveData = Get-WmiObject -class win32_LogicalDisk -computername "$computerName" -filter "Name = '$drive'"

if ($driveData.FreeSpace -lt $freeSpaceThreshold)
{
    $from = "myaddr@mycompany.com"
    $to = "myaddr@mycompany.com"
    $subject = "Low Disk Space!"
    $body = "Free Space Remaining: " + $driveData.FreeSpace
    $smtpServer = "smtp.mycompany.com"
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($from,$to,$subject,$body)
}
share|improve this answer
add comment

You can use this PowerShell v2 script to send an email when a drive gets to a certain level.

You could schedule it using "Scheduled Tasks", you will need to change the smtp details at the bottom of the script for your network.

Function DispDisk
{
$server=$server.toupper()
[float]$tempfloat = ($_.freespace/$_.size)*100
$Body= "`r`n$Server - Drive: $($_.Deviceid) has only $([math]::round(($tempfloat),1))% free" 
$Body+="`r`nTotal Size: $([math]::truncate($_.size / 1gb)) GB"
$Body+="`r`nFree Space: $([math]::truncate($_.freespace /1gb)) GB"
IF ($tempfloat -lt $PercenttoEmail)
{
Send-MailMessage -SmtpServer $SMTPServer -To $To -From $From -Subject "Disk Space Issue $Server $($_.Deviceid) is below $percenttoemail%" -Body $Body
}
}

#
# SMTP Settings, you will need to change these.
#

# The Server you want to check, this is the first arguments (example .\getdspace yourserver) would check the YourServer server
$server = $args[0]
# Percent to send an email, if its below this you should get an email
$PercenttoEmail =15
# Your SMTP Server
$SMTPServer="smtprelay.YourDomain.co.nz"
# Who gets the email
$To="You@YourDomain.co.nz"
# What address does the email Come From
$From="service.desk@YourDomain.co.nz"

get-wmiobject win32_logicaldisk -filter "DriveType=3" -computer $server | foreach-object {DispDisk}
share|improve this answer
add comment

There's some good recommendations here.

I administer a fairly large Nagios setup, but this would likely be overkill for what you need. Either way, Nagios (reference: NRPE_NT) contains various plugins that do exactly what you are requesting. However, you'd still have to write some code and potentially a Windows scheduler job to tie it all together.

I've not had cause, until now ;), to investigate a single tool that would take care of all of that in one fell swoop, so unfortunately I cannot point you towards a single program.

share|improve this answer
    
thanks, I searched but didn't find that (probably because I used the word "full"). If we did something with perfmon alerts would that have a perf impact at all? –  Kate Gregory Sep 2 '10 at 20:01
    
In my experiences, I've seen no performance issues with using perfmon. I've used perfmon quite a bit, even remotely monitoring numerous parameters and with logging with no obvious impact. –  Matt Sep 2 '10 at 20:33
add comment

Depending on how much time you want to spend on it, you could use a simple service like http://monguard.com which just does an inexpensive saas model approach to simple system monitoring. A few clicks and you're up and running.

Since they run in the cloud you don't have to worry about firewalls, etc. We are a consulting shop so this approach works great for us but may not be a fit depending on your situation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.