I need to programmatically (.NET 3.5, C#) monitor a SQL Server 2008 machine through WMI. I want to measure the number of batch requests per second that the server is receiving; this is what the Windows 7 Performance Monitor tool will show you under the SQL Server:SQL Statistics
category, Batch Requests/sec
counter. If I monitor the server using this tool, I observe a baseline of zero when the server is idle, going up to 100 or 200 when I hit it with some queries from my application.
Now, when I try to use the WMI classes in .NET to obtain the same data, I only read zeros, no matter how much I hit the server with queries. From what I have read on MSDN, some performance counters are not supposed to be retrieved instantaneously, but a sampling process is suggested. I could not find any information on which counters fall into this category, i.e. should I use sampling to measure batch requests per second? Also, what kind of sampling? I imagine that the Windows Performance Monitor tool is doing some calculations behind the scenes to show the graphs that it shows; I would like to obtain similar results. Anyone has gone through a similar experience and solved it successfully? Thanks.