Home > SQL Server Tips > Database Management and Administration > Checking the system drive space threshold in SQL Server
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATABASE MANAGEMENT AND ADMINISTRATION

Checking the system drive space threshold in SQL Server


SATISH GOPI
07.02.2002
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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
 )
As
 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
 else
 select @MinAllowed = 1024
 If @FreeSpace > @MinAllowed
 Select 'Plenty of space no need for alarm'  
 Else
  begin
   select @Servername=@@ServerName
   Select 'Drive ' + @DriveLetter + ' on ' + @ServerName + ' is below minimum threshold contact dba immediately'
   if @EmailTo is not null
    begin
     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 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.


Rate this Tip
To rate tips, you must be a member of SearchSQLServer.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Microsoft SQL Server Performance Monitoring and Tuning
Using traces in SQL Server Profiler
SQL Server Mailbag: CALs, witnesses and unwanted changes
SQL Server Mailbag: Data restoration and DB property management
Working with IntelliSense in SQL Server 2008 Management Studio
SQL Server Mailbag: Stored procedures, triggers and SSRS reports
Troubleshooting Distributed Transaction Coordinator errors in SQL Server
Clearing the Windows page file and its effect on server performance
Optimizing SQL Server indexes –- even when they're not your indexes
Performance implications of transaction log autogrowth in SQL Server
The short course on how SQL Server really works

Database Management and Administration
Password cracking tools for SQL Server
Using traces in SQL Server Profiler
Meet compliance requirements with improved database security practices
Hardening the network and OS for SQL Server security
Securing the server and database in SQL Server
How SQL Server 2008 components impact SharePoint implementations
Troubleshooting Distributed Transaction Coordinator errors in SQL Server
Achieving high availability and disaster recovery with SharePoint databases
Clearing the Windows page file and its effect on server performance
Deploying a SQL Server virtual appliance for Microsoft Hyper-V

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
contiguity  (SearchSQLServer.com)
contiguous  (SearchSQLServer.com)
drilldown  (SearchSQLServer.com)
hashing  (SearchSQLServer.com)
hybrid online analytical processing  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



SQL Server Development - .NET, C#, T-SQL, Visual Basic
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts