Solved

How to check the disk space of shared disk on cluster environment?

Posted on 2009-04-06
5
513 Views
Last Modified: 2012-05-06
We created all user databases on shared disk Lun1 and Lun2 on drive D: (Lun1 and Lun2 were subfolder undre drive D:). If I ran xp_fixeddrives, it would only tell me how much space left on drive D:,  and didnt tell me how much free space on the shared disk Lun1 and Lun2. Right I just manually checked by check the properties of Lun1 and Lun2 to get the information. Do you have any commands or any stored procedures for monitoring the disk space on shared disk?
Thanks!
0
Comment
Question by:luyan
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:MohammedU
ID: 24131648
You can try using DIR command with XP_CMDSHELL...
Check the following url...
http://bytes.com/groups/ms-sql/477715-check-diskspace-unc-via-t-sql
0
 

Author Comment

by:luyan
ID: 24226633
I could create the stored procedure sp_checkdbspace. But when I ran it, got the following error message.
Msg 208, Level 16, State 1, Procedure sp_checkdbspace, Line 52
Invalid object name 'msdb..DBSpaceHistory'.

0
 
LVL 15

Accepted Solution

by:
MohammedU earned 500 total points
ID: 24226949
You have to modify the proc...
Use the following...


CREATE procedure sp_checkdbspace
AS
SET nocount ON

CREATE TABLE #DriveList (
name varchar(20) null,
lowfree int null,
highfree int null,
mediatype int null
)

CREATE TABLE #DirList (
Drive varchar(20) null,
DirResults varchar(255) null
)

INSERT INTO #DriveList EXEC master.dbo.xp_availablemedia

DECLARE @Drive varchar(20),
@CMD varchar(255)

DECLARE mycursor CURSOR
FOR
SELECT name
FROM #DriveList
ORDER BY name

OPEN mycursor

FETCH mycursor INTO @Drive

IF CURSOR_STATUS('variable', '@mycursor') = 0
BEGIN
PRINT 'No such device'
CLOSE mycursor
DEALLOCATE mycursor
return
END

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @CMD = 'insert into #DirList (DirResults) EXEC
master..xp_cmdshell ''DIR /-C ' + @Drive + ''''
EXEC (@CMD)
UPDATE #DirList SET Drive = @Drive WHERE Drive IS NULL
FETCH mycursor INTO @Drive
END

CLOSE mycursor
DEALLOCATE mycursor


SELECT *, BytesFree = convert(numeric(18,0),
rtrim(ltrim(substring(replace(DirResults, ' bytes free', ''), 26,
50))))
INTO #SpaceOnDisk
FROM #DirList
WHERE DirResults LIKE '%bytes free%'



select Drive, DiskMBFree = convert(numeric(10,3), BytesFree / 1048576) from #SpaceOnDisk

drop table #DriveList, #SpaceOnDisk, #DirList
0
 

Author Comment

by:luyan
ID: 24251062
Thanks for your script. It's good to find the free space information for every drives. How can I get the information of different Lun (such as sub-directories D:\Lun1 and D:\Lun2) of storage device through running script?
I could get the information by running diskmgnt.msc.  How to put the output into report? I would like to get email of this report.
Thanks!
0
 

Author Closing Comment

by:luyan
ID: 31567166
Thanks!
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now