Search code examples
performancecounter

How does PerformanceCounter count current connections to IIS website?


We can use C# code or performance monitor in windows server to view current connections to IIS website.

  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());

This can return the connections number.

Is this counting the TCP connections under the hood? We know there are many TCP connection status like ESTABLISHED,TIME_WAIT, which status is performance counter counting?


Solution

  • Since nobody answers this post, I post my findings.

    In the server, I invoke the related code in the original post, and it returns 574.

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

    And then, I run the netstat command.The website is ocupying port 9010.

    netstat -an | find /i "9010"

    It returens 550 established TCP connections. So I guess it is monitoring established TCP connections.