DBA Monitoring Tool | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

DBA Monitoring Tool

Hi, I have got around 20 Sql Servers and 500+ Databases, What i have to do is to Write an Stored Proc which will go to each of the databases in all servers and Get the Datafile size and Log file size and insert into a Temp table in Monitoring DATABASE. and this SP will be run after every 1/2 Hour. so, i need to keep in mind the speed and locks on the database aswell. Can anybody plz help me in that???????[?] Regards,
Speed shouldn’t be a problem. you can use dbcc sqlperf(logspace) for the logs which reports on all databases on a server in one go. For the datafiles either use sp_spaceused, or run Pofiler against Eneterprise Manager when it’s preparing the taskpad view and see what it does, something a bit neater I seem to remember. It will be a relatively straighforward task to collect this information in tables in a central database. I should be achievable within 30 minutes so it could be run that frequently. Tom Pullen
DBA, Oxfam GB
Thanks Tom Pullen, But how do i run "dbcc sqlperf(logspace) and sp_spaceused" on other servers from my SP, becoz these commands takes the server on which we are running those commands. My output of the SP should be somthing like below: ***************************************************************************************
ServerName DBNAME RecordDateTime FileType Size Used Free %Used %Free
———- ——– ————— ——– —- —- —– —– —–
team9 Vasu 2004-11-18 14:56 Data1 0 1 62.50 37.50
team9 Vasu 2004-11-18 14:56 Log1 0 132.81 67.19
*************************************************************************************** I hope got got my Problem!!!!
You can create stored procedures on the remote server to execute these commands, then call them from the central server. E.g. on remote server (say, SERVER2, in the pubs database):- CREATE PROCEDURE prLogSpace
AS EXECUTE(dbcc sqlperf(logspace))
GO then schedule on the central server EXEC SERVER2.pubs.dbo.prLogSpace
you can do something similar for sp_spaceused, maybe use a cursor to loop through all the databases by looking up their names in sysdatabases. I shall leave the formatting and details up to you….
Tom Pullen
DBA, Oxfam GB
You can take help of SP_MSforeachdb which undocumented stored procedure to get the details, http://www.sql-server-performance.com/ac_sql_server_2000_undocumented_sp.asp
Sometimes, you need to perform the same actions for all tables in the database. You can create cursor for this purpose, or you can also use sp_MSforeachdb stored procedure to accomplish the same goal with less work. For example, you can use this stored procedure to run a CHECKDB for all the databases on your server. EXEC sp_MSforeachdb @command1="print ‘?’ DBCC CHECKDB (‘?’)"
Satya SKJ
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
I do something similar to this with a perl script. It uses a file in which I have a list of the servers to be monitored. Within a for loop, the script makes a connection to each server, runs a select on sysprocesses, and writes the result to a table on another server at the end. [In this case I am looking to see which servers are available, and how many connections are on each server.] You could simply replace the "select spid, dbid from sysprocesses " with a command of your choice. <br />All you need to maintain is the file with the list of servers in, so that all of your servers are monitored. <br /><br />===============================================================================================<br /><br />#!d:/perl/bin/perl.exe -w<br /># for documentation on MSSQL:<img src=’/community/emoticons/emotion-2.gif’ alt=’:D‘ />Blib see <br />use MSSQL:<img src=’/community/emoticons/emotion-2.gif’ alt=’:D‘ />Blib;<br />use strict;<br /><br /># basic error handling<br />sub error_handler;<br />dberrhandle ("main::error_handler");<br /><br /># Get the filenames from the file serverlist.txt<br /># Generate Filehandle – change as required<br />my $infile ="d:/apache/cgi-bin/serverlist.txt";<br />open (OF, "$infile") || die "$!";<br /><br /># Get row data elements into array<br />my @datain=&lt;OF&gt;;<br /><br /># Close Filehandle<br />close OF;<br /><br /># How many line are we dealing with – may be useful later<br />my $linecount [email protected] ;<br />my @countrows;<br /><br />#use this a a simple error check<br />my @serveravail;<br /><br /># a simple counter<br />my $counter =0;<br /><br />#set up connection parameters<br />my $status = dbsetlogintime(10);<br /><br /># these are for storing info returned from the server<br /># have as many of these as you need<br />my $spid;<br />my $dbid;<br /><br /><br /><br /># Log into each server<br />for ($counter=0; $counter &lt; $linecount; $counter++){<br />$serveravail[$counter]=1;<br />chomp $datain[$counter];<br />my $server =$datain[$counter];<br />my $dbh = MSSQL:<img src=’/community/emoticons/emotion-2.gif’ alt=’:D‘ />Blib-&gt;dblogin(‘MonitorUser’,"MonitorPassword", $server, ‘master’); <br />if ($serveravail[$counter]==1) {<br /> # use your choice of command here<br /> # maybe you want to query sysfiles<br />$dbh-&gt;dbcmd("SELECT spid, dbid FROM sysprocesses");<br />$dbh-&gt;dbsqlexec;<br />$dbh-&gt;dbresults;<br /> # run trough all the rows to extract any info you need <br />while (my %result = $dbh-&gt;dbnextrow(1)){<br /> # you can access the fields in your query like this:<br /> # $spid=$result{spid};<br /> # $dbid=$result{dbid};<br />}<br /> # you don’t need this, bit I am interested in how many connections <br /> # there are on each server<br />$countrows[$counter] = $dbh-&gt;DBCOUNT;<br /> # does what is says on the can<br />$dbh-&gt;dbclose;<br />}<br />}<br /><br />sub error_handler {<br /># simply set notavail flag<br />$serveravail[$counter]=99;<br />}<br /><br />my $srvstatus="NA";<br />my $conns =0;<br /><br /># write values to monitor db<br />my $dbh2 = MSSQL:<img src=’/community/emoticons/emotion-2.gif’ alt=’:D‘ />Blib-&gt;dblogin(‘MonitorUser’,"MonitorPassword","MonitorServer", ‘MonitorDB’); <br />$dbh2-&gt;dbcmd("delete from Monitor.dbo.tblStatus");<br />$dbh2-&gt;dbsqlexec;<br />$dbh2-&gt;dbresults; <br /># I knew it would be a good idea to know how many servers we are dealing with<br />for ($counter=0; $counter &lt; $linecount; $counter++){<br />my $server =’"’.$datain[$counter].’"’;<br /><br />if ($serveravail[$counter]==99){<br />$srvstatus=’"DOWN"’;<br />$conns=’"na"’;<br />}<br />else {<br />$srvstatus=’"UP"’;<br />$conns=$countrows[$counter];<br />}<br />$dbh2-&gt;dbcmd("INSERT into Monitor.dbo.tblStatus VALUES (".$server.", ".$srvstatus.", ".$conns.")");<br />$dbh2-&gt;dbsqlexec;<br />$dbh2-&gt;dbresults;<br />}<br />$dbh2-&gt;dbclose;<br /><br />===========================================================================================================<br /><br />You will need to create a login on each server to be monitored called monitoruser or similar, and make sure it has read access to the relevant tables (sysprocesses, sysfiles etc…)<br /><br /><br />I have other scripts do display the results as web pages through cgi, but this is a good gambit for collecting your database metadata.<br /><br />
But those 20 Servers are my customer servers, and i’m monitoring those servers from one of my central server "Team9" and thr is a server table which consists of this 20 server name ,now My main goal is, i’ll run a SP or a Query from "TEAM9", it should pick up the the server name from server table and get data from the respective servers. Plz HELP!!!!
You need to execute the above script using OSQL session to connect all the servers and schedule it as a job from Team9 server. Satya SKJ
This posting is provided “AS IS” with no rights for the sake of knowledge sharing.
FOR SELECT ServerName FROM ##ServerNameTemp OPEN ServerCursor FETCH NEXT FROM ServerCursor INTO @ServerName WHILE @@FETCH_STATUS = 0 BEGIN
SET @CmdStr = ‘osql -S ‘ + @ServerName + ‘ -E -n -h-1 -i"d:IT_DatabaseGetdblist.sql"’ INSERT INTO ##ServerDBNameTemp EXEC master..xp_cmdshell @CmdStr DELETE FROM ##ServerDBNameTemp
OR SUBSTRING (dbname, 2, 1) = ‘ ‘ INSERT INTO DatabaseInfoMaster (ServerName,DatabaseName)
SELECT @ServerName,ltrim(rtrim(DBname)) from ##ServerDBNameTemp
–UPDATE DatabaseInfoMaster FETCH NEXT FROM ServerCursor INTO @ServerName END CLOSE Servercursor
—————————— Satya, The problem is with output,it is not foramatted so i’m not able to take the output into table