如何通过sql server远程收集windows性能计数器
我希望我的应用程序(部署到数千个位置)能够监视自己的环境,特别是 sql server 框。当 SQL Server 位于本地时,这很容易做到,因为我可以使用 System.Diagnostics 库并通过它收集 Windows 性能计数器。然而,当 SQL Server 是远程时,我遇到了问题,因为我无法保证我的 C# 应用程序(在本例中为 Windows 服务)可以访问远程 SQL Server 计算机,除了我知道它可以访问 SQL Server 之外。
关于如何通过 SQL 从该机器收集 Windows 性能计数器有什么想法吗?
我想到的一种方法是使用 SQL CLR,但它似乎需要不安全的访问,我很确定我不想要这种访问。
谢谢
I'd like my application (which is deployed to thousands of locations) to be able to monitor its own environment, in particular the sql server box. When the SQL Server is local, this is easy to do as I can use the System.Diagnostics library and collect the windows performance counters through that. When the SQL server is remote however I have a problem because I cannot guarantee that my c# application (a windows service in this case) has access to the remote sql server machine OTHER THAN the fact that I know it can access the SQL Server.
Any ideas on how I can collect the windows performance counters off that machine through SQL?
One way I've thought of is to use SQL CLR, but it seems to require UNSAFE access, which I'm pretty sure I don't want.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
按照您在评论中所述标记
要么您必须在安装程序中编写某种功能,以确保您拥有适当的远程权限(如果没有管理员设置权限,可能不会安装)性能。柜台访问。
您没有准确说明您要监视的内容,但是,我是否建议使用内置的 SQL Server 动态管理视图 (DMV)
MSDN
好文章视频
非常有用的示例
这些在最近版本的 SQL Server 中变得非常强大,允许您监视在 perfmon 中使用的大部分统计数据(CPU、IO、内存等等)。也许没有 perfmon 那么多的粒度,但通常我发现它们比现在的 perfmon 更有用,可以快速获取相关数据。只要您的连接字符串用户具有管理员权限,您就不必担心服务器权限。这个功能已经内置到 sql-server 中了,看看吧。
编辑 ...
@Mark 这是我用来获取数据库上的 IO 时间的一些 DMV 脚本,不像 PerfMon 那样精确,但它允许您专注于特定的数据库文件。
查看“dm_io_virtual_file_stats”DMV
一些更奇特的东西......
Mark as you stated in the comments
Either you have to write some kind of functionality into your installer that is going to make sure you have the proper privileges (maybe won't install without admin setting privileges) for remote perf. counters access.
You didn't state exactly what you were trying to monitor, however, might I suggest using the built int SQL Server Dynamic Management Views (DMV's)
MSDN
Good Articles Videos
Very Useful Examples
these have become very robust in recent releases of SQL server and allow you to monitor the majority of the stats you would work with in perfmon (CPU, IO, MEMORY, many more). Perhaps not as much granularity as perfmon but usually I find them to be more useful then perfmon nowadays for quick pertinent data. And as long as your connection string user has admin rights you don't have to worry about server privileges. And this functionality is allready built into sql-server Give it a look see.
Edit ...
@Mark Here are some DMV scripts I use to get IO time on a database, not as exact as PerfMon however it allows you to focus in on a specific database file.
Check out the "dm_io_virtual_file_stats" DMV
Something a little fancier ...
如果对程序集进行签名,则可以从程序集创建登录名,授予其运行不安全程序集的服务器级权限,并从 dll 创建程序集。这允许您运行不安全的程序集,而无需打开数据库上的可信标志。
If you sign your assembly, you can create a login from the assembly, grant it the server-level permission to run unsafe assemblies, and create the assembly from the dll. This allows you to run unsafe assemblies w/o having to turn the trustworthy flag on the database on.
我认为为此您需要比自滚动 SQL CLR 更强大的东西。 MS 有一个专门用于此目的的工具,称为 SCOM。
我在 50 台服务器的环境中取得了非常好的结果。
您可以通过内置的时间点报告、数据仓库和警报来收集大量可配置数据。
优秀的维基百科文章
technet
I would think you need something more robust than self-rolled SQL CLR for this. MS has a tool for precisly this called SCOM.
I have had very good results in envs with 50 servers.
You collect loads of configurable data with built in point in time reports, data warehousing and alerts.
good wikipedia article
technet