Solved

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

Posted on 2009-04-06
5
514 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

785 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