How do I monitor the size of a Microsoft SQL Server Database

Votes:

0

Your Vote:

Up

Down

I have a Microsoft SQL Server 2008 that is used for Sharepoint. I would like to monitor the size of the database does anyone know how to accomplish this? I do not want to monitor the file size using WMI because UNC paths are not allowed and that would be a lot of mapped drives to monitor all the SQL Server databases I am responsible for.

Thanks in Advance

database query sql

Created on Apr 5, 2011 3:37:21 PM by  John D Johnson (0) 1



7 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

The database size can be obtained with system stored procedure sp_helpdb that is included in SQL 2008 and 2005 (not sure about 2000). We cannot use this stored procedure directly with PRTG as it returns to many rows and fields, so here is what we have to do:

Step 1

Create a new stored procedure using the following code

CREATE PROCEDURE [dbo].[spSpaceUsed]
	@name nvarchar(24)

AS
BEGIN
	SET NOCOUNT ON
	-- Create a tempory table
	DECLARE @SpaceUsed TABLE
	 (
	  name nvarchar(24), 
	  db_size nvarchar(13),
	  owner nvarchar(24),
	  dbid smallint,
	  created char(11),
	  status varchar(340),
	  compatibility_level tinyint
	  )

	--Populate the table
	INSERT INTO @SpaceUsed EXEC sp_helpdb

	--Select the size of the specified table
	SELECT
	  CONVERT (DECIMAL, REPLACE (db_size, 'MB', ''))
	  AS [size]
	  FROM @SpaceUsed
	  WHERE name = @name
END

Step 2

Add a new MSQL sensor

On your PRTG server, add a new MSQL sensor. Fill in the required fields and in the "SQL Expression" field enter

exec dbo.spSpaceUsed YOUR_DATABASE_NAME

In the channels tab select the value channel and enter MB as unit.

Created on Apr 5, 2011 7:28:59 PM by  Gerard Feijth (4,203) 3 2

Last change on Apr 28, 2011 3:39:54 PM by  Torsten Lindner [Paessler Support] (15,450) 3 1



Votes:

0

Your Vote:

Up

Down

I found an easier way of performing this request after a bit of wrestling. In the SQL Query field I used

select (convert(float,Size)*(1024*8))/1024/1024 from DatabaseName.dbo.sysfiles where GroupId = 1

Just replace "DatabaseName" with the database you are wanting to query.

Thanks for the reply

Created on Apr 5, 2011 8:15:59 PM by  John D Johnson (0) 1



Votes:

0

Your Vote:

Up

Down

You are right, that is an easier way, but it will also include the log file size and not only the database size.

Created on Apr 6, 2011 12:09:46 PM by  Gerard Feijth (4,203) 3 2



Votes:

0

Your Vote:

Up

Down

You are correct, I need to sit down and decide exactly what it is that i am wanting to monitor. Thanks for pointing that out.

Created on Apr 6, 2011 2:03:28 PM by  John D Johnson (0) 1



Votes:

0

Your Vote:

Up

Down

If i use your procedure and your sql expression, i receive following error message: "Could not perform query: Database Server Error: Zeichenfolgen- oder Binärdaten würden abgeschnitten." (i'm not sure if my translation would be the same as yours - so it's german)

Created on Apr 28, 2011 3:01:24 PM by  AGriese (0) 1



Votes:

0

Your Vote:

Up

Down

In that case the system stored procedure sp_helpdb returns “lager” data than the tempory table @SpaceUsed is set up for.

Run sp_helpdb in a new query window, see what the output is and adjust the field sizes of the tempory table accordingly.

Created on Apr 28, 2011 3:26:44 PM by  Gerard Feijth (4,203) 3 2



Votes:

0

Your Vote:

Up

Down

After adjusting the field sizes (name is up to 60 digits!) the error was removed. But the value field is '0' (no error but nothing in). When i run the sp_helpdp everything seems okay and all values correspond with the size of the db files.

Created on May 4, 2011 1:43:35 PM by  AGriese (0) 1



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.

PRTG
Network Monitor
Intuitive to Use.
Easy to manage.

150.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Visit
www.paessler.com

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

Top Tags


View all Tags