如何从数据库中的任务管理器存储CPU和内存利用率 [英] How to Store CPU and Memory Utilization from task manager in Database

查看:284
本文介绍了如何从数据库中的任务管理器存储CPU和内存利用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望每隔5分钟后存储所有单个任务的CPU和内存利用率。从任务管理器到数据库,说SQL数据库。是否可以在C#中编写一个控制台应用程序,它可以完成此任务并将利用率存储在SQL表中。

解决方案

您可以使用<$获取此信息 System.Diagnostics.PerformanceCounter

http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx [ ^ ]。



你可以使用这篇介绍CodeProject的文章介绍了如何做到这一点:性能计数器简介 [ ^ ]。< br $> b $ b

-SA

实际上你到目前为止所获得的所有信息都是正确的:

- 任务管理器只是一个显示数据的工具。它没有收集任何东西

- 在任务管理器(以及其他类似的)的背景下是系统级工具,如WMI,正如Mike Meinz强调的那样。

- 而你也可以使用.net框架提供的性能计数器工具轻松访问它们,如谢尔盖建议的那样。



不过,我想提请你注意内置功能你可以用来实现相同的结果,没有任何代码在你身边。众所周知的PerfMon工具具有可用于将结果存储到数据库中的功能。请参阅以下文章: http://www.sepago.de/e/nicholas/2009/11/02/performance-monitoring-part-7-using-performance-monitor-with-a-database [ ^ ]。

I want to store the CPU and Memory Utilization of all the individual tasks after every 5 mins. from the task manager into a DB, say SQL Database. Is it possible to write a console application in C# which can accomplish this task and store the utilization in SQL Table.

解决方案

You can get this information is you use System.Diagnostics.PerformanceCounter:
http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx[^].

You can use this introductory CodeProject article to see how to do things: An Introduction To Performance Counters[^].

—SA


Actually all the information you got so far is correct:
- Task manager is just a tool to display data. It is not collecting anything
- In the background of task manager (and others like this) are system level tools, like WMI, as Mike Meinz highlighted.
- And you can access them easily also with performance counter tools provided by the .net framework as Sergey suggested.

Still, I would like to draw your attention towards built-in features you can use to achieve much the same result with no code at all from your side. The well-known PerfMon tool has features you can use to store your results into a database. Please see following article: http://www.sepago.de/e/nicholas/2009/11/02/performance-monitoring-part-7-using-performance-monitor-with-a-database[^].


这篇关于如何从数据库中的任务管理器存储CPU和内存利用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆