Thursday, March 12, 2009

Start Data Collector Set of Reliability & Performance Monitor from C#

Reliability & Performance Monitor a.k.a perfmon is a valuable tool to have for a Database Administrator, as it provides various counters to measure your system with defined time interval.

Data Collector Sets (Similar to Counter Logs in Windows 2003 and XP or before versions)  will give you the opportunity to collect these data to file so that it can be analyzed later.

image

In the Data Collect Set, you need to start the defined Data Collector Set. Problem here is if you want to analyze something soon after you do it, there will be a time delay. For example, if you want to measure % of Processor soon after the execution of a stored procedure. Normally, you need to execute the stored procedure and manually start the Data Collector Set which lead to some delay. Instead, you can include both the executing the Stored Procedure and starting the Data Collector Sets inside a C# or VB.net application.

So the next question is, how to start Data Collector Sets from C#. Though you have perfmon with previous versions of OS you can start Data Collector Sets from C# only with Vista and Windows 2008.

First, add PLALibrary to the reference from the %windir%\System32\PLA.dll and include using PlaLibrary; at the top of your code. Following code will start, Data Collector Set named Page Split.

private void Start_PLA()
        {
            IDataCollectorSet cs = new DataCollectorSetClass();
            string name = "Page Split";
            cs.Query(name, null);
            cs.start(false);
        }

Similarly, there are many functions available with PLALibrary for other operations like, Create and Stop Data Collector Sets.

No comments:

Post a Comment