aspnet aspnet获取几台服务器的cpu和内存使用率

来源:互联网  时间:2016/7/7 0:11:52

关于网友提出的“aspnet aspnet获取几台服务器的cpu和内存使用率”问题疑问,本网通过在网上对“aspnet aspnet获取几台服务器的cpu和内存使用率”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:aspnet aspnet获取几台服务器的cpu和内存使用率
描述:

我公司现需要检测网站服务器的cpu及内存使用率,需在网站上添加一个页面,其中包含个web服务器和数据库服务器的cpu及内存使用率。
加急!!!!!


解决方案1:

使用此方法创建新的 Process 组件的数组,并将它们与指定(通常为远程)计算机上的所有进程资源关联。该进程资源必须已经存在于本地计算机上,因为 GetProcesses 不创建系统资源,而是将资源与应用程序生成的 Process 组件进行关联。因为操作系统本身正在运行后台进程,所以此数组永远不为空。
如果不希望检索在计算机上运行的所有进程,则可以使用 GetProcessById 或 GetProcessesByName 方法限制它们的数量。GetProcessById 创建 Process 组件,该组件与系统上由传递给该方法的进程标识符标识的进程关联。GetProcessesByName 创建 Process 组件的数组,这些组件的关联进程资源共享传递给该方法的可执行文件。
GetProcesses 方法的此重载通常用来检索网络中远程计算机上运行的进程资源列表,但您可以通过传递“.”来指定本地计算机。
Windows 98, Windows Millennium Edition 平台说明:
Windows 98 或 Windows Millennium Edition (Windows Me) 上不支持 machineName 参数。
示例
下面的示例检索的信息涉及当前进程、本地计算机上运行的“记事本”的所有实例、在使用计算机别名和 IP 地址的特定计算机上运行的“记事本”的所有实例、本地计算机和远程计算机上运行的所有进程,以及本地计算机或远程计算机上使用进程 ID 的特定进程。
Visual Basic  复制代码 
Imports System
Imports System.Diagnostics
Imports System.ComponentModel
Namespace MyProcessSample
    _
   '/ 


   '/ Shell for the sample.
   '/ 

   Class MyProcess
      Sub BindToRunningProcesses()
         ' Get the current process.
         Dim currentProcess As Process = Process.GetCurrentProcess()
         ' Get all instances of Notepad running on the local
         ' computer.
         Dim localByName As Process() = Process.GetProcessesByName("notepad")
         ' Get all instances of Notepad running on the specifiec
         ' computer.
         ' 1. Using the computer alias (do not precede with "\\").
         Dim remoteByName As Process() = Process.GetProcessesByName("notepad", "myComputer")
         ' 2. Using an IP address to specify the machineName parameter. 
         Dim ipByName As Process() = Process.GetProcessesByName("notepad", "169.0.0.0")
         ' Get all processes running on the local computer.
         Dim localAll As Process() = Process.GetProcesses()
         ' Get all processes running on the remote computer.
         Dim remoteAll As Process() = Process.GetProcesses("myComputer")
         ' Get a process on the local computer, using the process id.
         Dim localById As Process = Process.GetProcessById(1234)
         ' Get a process on a remote computer, using the process id.
         Dim remoteById As Process = Process.GetProcessById(2345, "myComputer")
      End Sub 'BindToRunningProcesses
      Shared Sub Main()
         Dim myProcess As New MyProcess()
         myProcess.BindToRunningProcesses()
      End Sub 'Main 
   End Class 'MyProcess
End Namespace 'MyProcessSample
 
C#  复制代码 
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
/// 
/// Shell for the sample.
/// 

class MyProcess
{
   
void BindToRunningProcesses()
{
// Get the current process.
Process currentProcess = Process.GetCurrentProcess();
// Get all instances of Notepad running on the local
// computer.
Process [] localByName = Process.GetProcessesByName("notepad");
// Get all instances of Notepad running on the specifiec
// computer.
// 1. Using the computer alias (do not precede with "\\").
Process [] remoteByName = Process.GetProcessesByName("notepad", "myComputer");
// 2. Using an IP address to specify the machineName parameter. 
Process [] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");
// Get all processes running on the local computer.
Process [] localAll = Process.GetProcesses();
// Get all processes running on the remote computer.
Process [] remoteAll = Process.GetProcesses("myComputer");
// Get a process on the local computer, using the process id.
Process localById = Process.GetProcessById(1234);
// Get a process on a remote computer, using the process id.
Process remoteById = Process.GetProcessById(2345, "myComputer");
}
static void Main()
{
            MyProcess myProcess = new MyProcess();
myProcess.BindToRunningProcesses();
         }
}
}
 

解决方案2:


string temp = ((Double)System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + "M";
string temp1 = ((TimeSpan)System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime).TotalSeconds.ToString("N0");

上一篇求动态生成html实例
下一篇关于aspnet + mysql的发布问题!急啊!!!!
明星图片
相关文章
《aspnet aspnet获取几台服务器的cpu和内存使用率》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)