通过 WMI 监控 SQL Server 上每秒的批处理请求

发布于 2024-09-25 13:01:05 字数 471 浏览 0 评论 0原文

我需要以编程方式(.NET 3.5、C#)通过 WMI 监视 SQL Server 2008 计算机。我想测量服务器每秒接收的批量请求数;这是 Windows 7 性能监视器工具将在 SQL Server:SQL 统计信息 类别、Batch Requests/sec 计数器下向您显示的内容。如果我使用此工具监控服务器,当服务器空闲时,我会观察到基线为零,当我通过应用程序进行一些查询时,基线会上升到 100 或 200。

现在,当我尝试使用 .NET 中的 WMI 类来获取相同的数据时,无论我对服务器进行多少次查询,我都只读取零。根据我在 MSDN 上读到的内容,某些性能计数器不应该立即检索,但建议进行采样过程。我找不到有关哪些计数器属于此类别的任何信息,即我应该使用采样来测量每秒的批量请求吗?另外,什么样的抽样?我想象 Windows 性能监视器工具正在幕后进行一些计算以显示它所显示的图表;我想获得类似的结果。有谁有过类似经历并成功解决的吗?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不…忘初心 2024-10-02 13:01:05

是的,这是准确的。您的代码需要执行与 Perfmon 相同的操作:每秒查询一次性能计数器以获得有意义的值。您需要一个计时器或(呃)调用 Sleep()。顺便说一句,使用 PerformanceCounter 类是执行此操作的更好方法,WMI 并不便宜。这还使您可以访问 PerformanceCounter 属性,该属性告诉您它是什么类型的计数器。没关系,你知道无论如何你都需要计时器。

Yes, that's accurate. It is up to your code to do the same thing that Perfmon does: query the performance counter once a second to get a meaningful value. You'll need a timer or (ugh) call Sleep(). Using the PerformanceCounter class is the better way to do this btw, WMI is not cheap. That also gives you access to the PerformanceCounter property which tells you what kind of counter it is. Doesn't really matter, you know you need the timer anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文