请帮我程序来监控C#中的服务器 [英] Please help me program to monitor server in C#

查看:62
本文介绍了请帮我程序来监控C#中的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求我创建一个使用C#语言监视服务器性能的程序.是否有类似的程序?

解决方案

您应尝试使用PerfMon:

http://博客. msdn.com/b/securitytools/archive/2009/11/04/how-to-use-perfmon-in-windows-7.aspx [ http://msdn.microsoft.com/en-us/library/s80a75e5%28v = vs.90%29.aspx [ ^ ].

(对不起,本文仅适用于v.3.5及以下版本,但方法本身尚未过时.请查看本文引用的每种方法的MSDN帮助,以查找您需要的.NET Framework版本.) >
您可以总结感兴趣的所有进程的内存使用情况.您可以使用类System.Diagnostics.Process及其方法之一GetProcessesGetProcessesByName获取一系列进程,请参阅:
http://msdn.microsoft.com/en-us/library/system.diagnostics. process.aspx [^ ].

—SA


现在,让我们来看看如何监视硬盘驱动器.

您可以使用类System.IO.DriveInfo,请参见 http://msdn.microsoft.com /en-us/library/system.io.driveinfo.aspx [ ^ ].

 DriveInfo []驱动器= DriveInfo.GetDrives();
 foreach (驱动器驱动器 in 驱动器中的驱动器){
   如果(drive.IsReady){
        freeSpace = drive.TotalFreeSpace;
        size = drive.TotalSize;
       字符串 name = drive.Name;
       // 有关其他驱动器属性,请参见MSDN帮助页面参考信息
       //  ... 
       ReportDriveInfo(freeSpace,大小,名称/*  ,... */)); // 需要哪些东西来进行混音
   } 其他
      // 可以处理未就绪的驱动器;通常不会发生
} 



另外,您可以使用推送技术( http://en.wikipedia.org/wiki/Push_technology [ ^ ]).您可以订阅一些文件系统事件,而不是定期轮询数据(通常情况不太好),并且在基本内容没有任何变化的情况下避免轮询数据.为此,您可以使用类System.IO.FileSystemWatcher;请参阅:
http://msdn.microsoft.com/en-us/library/system.io. filesystemwatcher.aspx [ ^ ].

如果您还记得文件操作相对昂贵的情况,那么您可能会发现推技术非常有用,因此您希望减少轮询次数.

—SA


Required me to create a program that monitors the performance of the server By C # language .. Are there similar programs??

解决方案

You should try PerfMon:

http://blogs.msdn.com/b/securitytools/archive/2009/11/04/how-to-use-perfmon-in-windows-7.aspx[^]


This is a big question. Let''s do one step at a time.

Let''s start with memory usage:

To monitor memory usage, you can use System.Diagnostics. Please see how to monitor memory per-process:
http://msdn.microsoft.com/en-us/library/s80a75e5%28v=vs.90%29.aspx[^].

(Sorry, the article is only for v.3.5 and below, but the methods themselves are not obsolete. Please check the MSDN help on each method referenced in this article to find the version for .NET Framework version you nee.)

You can summarize the memory usage by all processes you are interested in. You can get the an array of processes using the class System.Diagnostics.Process and one of its methods GetProcesses or GetProcessesByName, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

—SA


Now, let''s see how to monitor hard drives.

You can use the class System.IO.DriveInfo, please see http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx[^].

DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
   if (drive.IsReady) {
       long freeSpace = drive.TotalFreeSpace;
       long size = drive.TotalSize;
       string name = drive.Name;
       //see the MSDN help page reference info for other drive properties
       //...
       ReportDriveInfo(freeSpace, size, name /* , ... */); //whatever you need for monotoring
   } else
      // do something to deal with non-ready drive; normally, it should not happen
}



Also, you can use push technology (http://en.wikipedia.org/wiki/Push_technology[^]) in monitoring drives. Instead of polling data periodically, which is always not very good, you can subscribe to some file system events and avoid polling data if nothing essential has changed. For this purpose, you can use the class System.IO.FileSystemWatcher; please see:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^].

You may find the idea of push technology very useful if you remember that file operations are relatively expensive, so you want to reduce number of polls.

—SA


这篇关于请帮我程序来监控C#中的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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