Monitoring batch queries per second on SQL Server through WMI

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 receives; is that the tool Windows 7 Performance Monitor displays in the category SQL Server:SQL Statistics, Batch Requests/sec. If I track a server using this tool, I observe a baseline of zero when the server is idle, up to 100 or 200 when I hit it with some requests from my application.

Now, when I try to use WMI classes in .NET to get the same data, I only read zeros, no matter how hard I got to the server with the requests. From what I read on MSDN, some performance counters should not get instantly, but sampling is suggested. I could not find information about which counters fall into this category, i.e. Should sampling be used to measure batch requests per second? Also, what choice? I believe that the Windows performance analysis tool does some calculations behind the scenes to show the graphs it shows; I would like to get similar results. Did someone go through a similar experience and successfully solve it? Thank.

+3
source share
1 answer

Yes, that's for sure. It depends on your code to do the same thing as Perfmon: request a performance counter once per second to get a meaningful value. You will need a timer or a call to Sleep (). Using the PerformanceCounter class is the best way to do this; WMI is not cheap. It also gives you access to the PerformanceCounter property, which tells you which counter it has. It doesn't matter, you know you need a timer.

+1
source

Source: https://habr.com/ru/post/1767157/


All Articles