我正在开发一个显示服务器数据和状态的C#项目。除其他事项外,我希望显示以下数据:
1)服务器上的开放套接字数量(简单)超过某个端口(硬)。
2)CPU和RAM的使用。
关于数字1,我需要您使用特定端口部分的帮助....
关于数字2,我使用的是PerformanceCounter,它在本地工作但在服务器中我得到“System.UnauthorizedAccessException:访问注册表项'Global'被拒绝”。我怎么能克服这个?
提前感谢
编辑:我在第1号尝试做的代码片段:
// 1. How many users are connected (checking how many open sockets to port 5000)
int count = 0;
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
{
if (tcpi.LocalEndPoint.Port == 5000)
{
count++;
}
}
另一个编辑:我已经在这个伟大主题的帮助下解决了第二个问题:Registry access error when Migrating ASP.NET application to IIS7