Solved

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

Posted on 2009-04-06
5
518 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

630 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