代码之家  ›  专栏  ›  技术社区  ›  Robin Sun

PerformanceCounter如何计算到IIS网站的当前连接数?

  •  0
  • Robin Sun  · 技术社区  · 7 年前

    我们可以在Windows服务器中使用C代码或性能监视器来查看到IIS网站的当前连接。

      PerformanceCounter performanceCounter = new System.Diagnostics.PerformanceCounter();
      performanceCounter.CategoryName = "Web Service";
      performanceCounter.CounterName = "Current Connections";
      performanceCounter.InstanceName = "SMS_Collection_CFC";
      string data = string.Format("{0}\t{1} = {2}", performanceCounter.CategoryName,
                    performanceCounter.CounterName, performanceCounter.NextValue());
    

    这可以返回连接号。

    这是在计算引擎盖下的TCP连接吗?我们知道有许多TCP连接状态,如已建立、等待时间、哪个状态是性能计数器计数?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Robin Sun    7 年前

    因为没有人回答这篇文章,所以我把我的发现贴出来。

    在服务器中,我调用原始日志中的相关代码,它返回574。

    string data = string.Format("{0}\t{1} = {2}", performanceCounter.CategoryName,
                performanceCounter.CounterName, performanceCounter.NextValue());
    

    然后,我运行netstat命令,该网站的焦点是端口9010。

    netstat-an查找/i“9010”

    它恢复550个已建立的TCP连接。所以我猜它是在监视已建立的TCP连接。

    推荐文章