Friday, February 24, 2012

Capturing database size on a schedule and graphing?

I'm wondering if there are any other programmers/DBA's out there that have
lots of databases that they need to routinely monitor its file growth over
time. I'm looking for any VB code or scripts that accomplish this.
We have about 500 SQL Server databases on one of our servers and they extend
daily.
I would like to capture their size and save the data so it can be graphed in
Excel or something to show the growth rate of each database.
If anyone has any sample code or idea how I can do some of this -- I would
appreciate it greatly.There are multiple ways you could do this.
One would be a scheduled job in SQL Server, which uses either the
undocumented sp_MSForEachDB or a cursor, loops through the databases, and
logs the result of sp_helpfile. This can be useful if you want to leave out
irrelevant databases using the where clause for the cursor or an if
conditional.
Another way would be a windows scheduled task that calls a VBS script, using
FileSystemObject to loop through all the MDF/NDF files and logs their size
property. This can be useful if all of your relevant databases are in a
specific location, separate from the system databases and/or other databases
you are not interested in logging.
If you can wait a day or two, I will whip something up that should be a bit
more concrete than the above... in the meantime, you could take a crack at
it, and post here if you have specific issues.
Let's narrow the discussion groups down though, okay?
http://www.aspfaq.com/
(Reverse address to reply.)
"DavidM" <spam@.spam.net> wrote in message
news:uBE#1Bb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
> I'm wondering if there are any other programmers/DBA's out there that have
> lots of databases that they need to routinely monitor its file growth over
> time. I'm looking for any VB code or scripts that accomplish this.
> We have about 500 SQL Server databases on one of our servers and they
extend
> daily.
> I would like to capture their size and save the data so it can be graphed
in
> Excel or something to show the growth rate of each database.
> If anyone has any sample code or idea how I can do some of this -- I would
> appreciate it greatly.
>
>|||Hi
You may want to check out the code in sp_spaceused and adapt it to suit your
purposes.
John
"DavidM" <spam@.spam.net> wrote in message
news:uBE%231Bb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
> I'm wondering if there are any other programmers/DBA's out there that have
> lots of databases that they need to routinely monitor its file growth over
> time. I'm looking for any VB code or scripts that accomplish this.
> We have about 500 SQL Server databases on one of our servers and they
> extend daily.
> I would like to capture their size and save the data so it can be graphed
> in Excel or something to show the growth rate of each database.
> If anyone has any sample code or idea how I can do some of this -- I would
> appreciate it greatly.
>
>|||...also sp_databases would probably do this if you don't want to split up
log and data files.
John
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:eR1GFfb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
> Hi
> You may want to check out the code in sp_spaceused and adapt it to suit
> your purposes.
> John
> "DavidM" <spam@.spam.net> wrote in message
> news:uBE%231Bb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
>|||There are some code can be used on this web site:
http://www.sqlservercentral.com/scr...ibutions/31.asp
I tried it, seems very nice.
Good luck
"DavidM" <spam@.spam.net> wrote in message
news:uBE%231Bb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
> I'm wondering if there are any other programmers/DBA's out there that have
> lots of databases that they need to routinely monitor its file growth over
> time. I'm looking for any VB code or scripts that accomplish this.
> We have about 500 SQL Server databases on one of our servers and they
extend
> daily.
> I would like to capture their size and save the data so it can be graphed
in
> Excel or something to show the growth rate of each database.
> If anyone has any sample code or idea how I can do some of this -- I would
> appreciate it greatly.
>
>|||If I run a query on the .sysfiles table, the size column shows 1704. Is
this in pages? How do I convert to bytes or megabytes?
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:eR1GFfb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
> Hi
> You may want to check out the code in sp_spaceused and adapt it to suit
> your purposes.
> John
> "DavidM" <spam@.spam.net> wrote in message
> news:uBE%231Bb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
>|||> If I run a query on the .sysfiles table, the size column shows 1704. Is
> this in pages? How do I convert to bytes or megabytes?
SELECT
[Filename],
[SIZE IN KB] = size*8
FROM sysfiles|||Thanks for the reply. I was able to find
http://www.databasejournal.com/feat...cle.php/3339681 which
looks promising.
I got this to work but its a bit kludgy. Since I have a VB application that
we run daily, I'd like to incorporate the collection of stats within this
program.
Next question is, what is the best way to graph this data using Excel? Can
I have Excel read the database/table directory from SQL? If so, that is
what I want to do rather than create a .CSV file from SQL.
Opinions?
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OG7fWJb7EHA.1408@.TK2MSFTNGP10.phx.gbl...
> There are multiple ways you could do this.
> One would be a scheduled job in SQL Server, which uses either the
> undocumented sp_MSForEachDB or a cursor, loops through the databases, and
> logs the result of sp_helpfile. This can be useful if you want to leave
> out
> irrelevant databases using the where clause for the cursor or an if
> conditional.
> Another way would be a windows scheduled task that calls a VBS script,
> using
> FileSystemObject to loop through all the MDF/NDF files and logs their size
> property. This can be useful if all of your relevant databases are in a
> specific location, separate from the system databases and/or other
> databases
> you are not interested in logging.
> If you can wait a day or two, I will whip something up that should be a
> bit
> more concrete than the above... in the meantime, you could take a crack at
> it, and post here if you have specific issues.
> Let's narrow the discussion groups down though, okay?
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "DavidM" <spam@.spam.net> wrote in message
> news:uBE#1Bb7EHA.2804@.TK2MSFTNGP15.phx.gbl...
> extend
> in
>|||> Next question is, what is the best way to graph this data using Excel?
Have you considered using Reporting Services?|||or you might wish to setup a sql agent job to run at the end of each busines
s
day to collect the information and popuate a base table
-- try the simple but useful approach below
/** the following can be quite useful **/
select instance_name,cntr_value 'Size in (Kb)' from
master..sysperfinfo(nolock)
where object_name like '%databases%'
and counter_name = 'Data File(s) size (Kb)'
and instance_name not in ('_total') -- can include total to get a server
based overview
"DavidM" wrote:

> I'm wondering if there are any other programmers/DBA's out there that have
> lots of databases that they need to routinely monitor its file growth over
> time. I'm looking for any VB code or scripts that accomplish this.
> We have about 500 SQL Server databases on one of our servers and they exte
nd
> daily.
> I would like to capture their size and save the data so it can be graphed
in
> Excel or something to show the growth rate of each database.
> If anyone has any sample code or idea how I can do some of this -- I would
> appreciate it greatly.
>
>

No comments:

Post a Comment