Checking the system drive space threshold in SQL Server

Here is how to check the system drive space threshold in SQL Server. (You'll need to install SQL Mail first.)

  1. Create the stored procedure (System_DriveSpace).
  2. Execute the stored procedure as a job with parameters (Drive, Threshold, Global email address/individual email address).

1. Create the following stored procedure:

CREATE Procedure System_DriveSpace
 @DriveLetter char(1),
 @Threshold integer = null,
 @EmailTo varchar(100) = null
 set nocount on
 declare @FreeSpace integer
 declare @MinAllowed integer
 declare @EmailMsg varchar(200)
 declare @EmailSub varchar (200)
 declare @ServerName varchar(20)
 create table #tmp_DiskSize
  (drive varchar(2), 
  MB_free INT
 insert into #tmp_DiskSize
 exec master..xp_fixeddrives

select @FreeSpace = MB_free from #tmp_DiskSize 
where drive = @DriveLetter
if @Threshold is not null
 select @MinAllowed = @Threshold
 select @MinAllowed = 1024
 If @FreeSpace > @MinAllowed
 Select 'Plenty of space no need for alarm'  
   select @Servername=@@ServerName
   Select 'Drive ' + @DriveLetter + ' on ' + @ServerName + ' is below minimum threshold contact dba immediately'
   if @EmailTo is not null
     select @EmailMsg = 'Drive ' + @DriveLetter + ' is below minimum threshold on ' + @ServerName + '.  Only ' + cast(@FreeSpace as varchar) + 'Mb remaining.  Escalate to DBA and  Infrastructure team immediately'
     select @EmailSub =  '**** CRITICAL CONDITION

    Requires Free Membership to View

on ' + @ServerName + ' ****' EXEC master.dbo.xp_sendmail @recipients = @EmailTo, @subject = @EmailSub, @message = @EmailMsg end end drop table #tmp_DiskSize return

2. Create the following job:

exec master..system_drivespace 'C', '512', 'sqlmonitors@abc.com'
exec master..system_drivespace 'D', '1024', 'sqlmonitors@abc.com'
exec master..system_drivespace 'E', '2048', 'sqlmonitors@abc.com'

Now, schedule the job accordingly.

This was first published in February 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.