Problem You have about 100 SQL Servers installed in your production environment. You have performance problems on few of the servers, but they happen during the time when you are not watching the servers. So, how can you automate performance statistics collection on all the servers around the clock so we have the statistics for 24/7/365.
Solution You can use the built-in windows utility "logman" that comes free.
Logman is the command line utility for Perfmon. Thru logman, it is easy to automate perfmon data collection which I will show you below.
First, we need to identify what Objects and Counters we need. From my experience, the below counters are good from a SQL Server point of view. We can automate creating one perfmon log file for each day. Then move the old files to a network share for later reference.
Cut and paste the contents below to a file name "SQL2005BaselineCounters.config" and save the file in "E:\perflogs". You can choose any local drive/folder, make sure there is enough space in it. Try not to use the same storage that your SQL Server databases use, because this can slow down your I/O throughput.
Note in the below code I am collecting SQL Server data for an instance named "MSSQL$DEV". This will need to be replaced for your server. If you just have a default instance this will just be "SQLServer"
This will create a new counter log named "SQL2005Perf". To verify this, open perfmon and click "counter logs" under Performance logs and alerts.
Here is the notes for each option used above:
SQL2005Perf - name of the counter log
-f bin - binary format, with a .blg extension
-b 01/01/2009 00:00:05 - begin data and time, input a datetime to start the counter log at a later time, if you input a datetime that is past, the counter log will start immediately
-E 01/01/2009 23:59:00 - end date and time
-si 05 - 5 second interval
-v mmddhhmm - filename will be named as SQL2005Perf_mmddhhmm.blg
-o "E:\perflogs\SQL2005Perf" - output folder name
-cf "E:\perflogs\SQL2005BaselineCounters.config" - config file name with the counters
-u domain\username * - the * will prompt for the password for the domain user account.
You can manually start and stop the above counter logs with below commands:
Logman start SQL2005Perf
Logman stop SQL2005Perf
To get a list of all your counter logs you can run this command.
Automate Data Collection
It would be nice if we have performance data for each day. This can be done by stopping the counter log at 11:59:59 PM and again starting it at 12:00:01 AM daily. Once you stop the counter log the log file is closed and starting the counter log creates a new log file.
Lets create a scheduled task which will do this.
Lets first create a batch file "StopCopyStart.bat" that will be executed by the scheduled task. Copy the contents below and save it in the folder "E:\perflogs". Make sure to change the "Servername", "SourceServerName" to match your servers.
/tn "Stop Copy And Start SQL2005Perf Perfmon Counter Log" - scheduled task name
/tr E:\perflogs\StopCopyStart.bat - run this batch file
/sc daily /st 23:59:59 - schedule time
/ed 01/01/2099 - end date
/ru system -user account
A new scheduled task with name "Stop Copy And Start SQL2005Perf Perfmon Counter Log" will now be created. From the command prompt type "schtasks", this will list all the scheduled tasks.
The idea is to move the performance data .blg file from each of the SQL Server to a common share. Create one folder for each server and move the .blg file there. So, the user account to execute the scheduled task should have permissions on the share where we move the performance log file.
You should do some housekeeping on this network share to delete files older than 30 or 60 days.
Always have one week ( one file for each day of week ) performance data for each server to be used as a baseline. If you have any performance problems you can compare with the baseline.
Last Update: 6/19/2009
About the author
Ranga Narasimhan has been in IT for over 10 years working on Siebel, Visual Basic, Crystal Reports and SQL Server.
So I've been using this technique for years across my database environment (but write directly into a SQL DB and use our monitoring page to aggregate and average out readings over a minute for live perfmon stats), but since I upgraded (in-place) all my clusters to SQL 2008 from SQL 2005 (still on WIndows 2003) I can no longer connect to any of the cluster names via perfmon from my remote perfmon box. I just instantly get the error "Unable to Connect to Machine". I can connect to the host names but that's not gonna work as I need the virtual names.
All SQL 2008 instances on single boxes work fine, even ones with Windows Server 2008.