Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find number of visitors/users at my site (IIS7/asp.net) at any given moment?

I need to display how many users are browsing my site. The site is running on iis7, and we are using asp.net 3.5.

Is the number of active sessions a good way to go? The number does not need to be very accurate.

No history is needed, I just want to know how many users are "online" right now, and display that on the page itself.

like image 323
oekstrem Avatar asked Apr 27 '10 09:04

oekstrem


People also ask

How do I see the number of concurrent users in IIS?

The easiest way to determine the number of active user sessions on the IIS Web site is to use the performance counters in Windows Performance Monitor. Open the Performance Monitor console by running the perfmon command and go the Performance monitor section (Monitoring Tools — > Performance Monitor).

How do you tell if IIS is being used?

In order to check if IIS is installed on your computer press Windows + R and then type inetmgr and press OK. If IIS configuration screen is displayed then IIS is installed on your computer.


3 Answers

You can use Windows Performance counters for this (perfmon)

ASP.NET Applications > Sessions Active counter.

You can access these performance counters using the System.Diagnostics namespace.

This code worked for me:

        PerformanceCounter pc = new PerformanceCounter("ASP.NET Applications",
     "Sessions Active", "__Total__", "MYSERVERHOSTNAME.domain");

        while (true)
        {
            Console.WriteLine(pc.NextValue());
            System.Threading.Thread.Sleep(1000);
        }

I had this problem so take a look here if the counter seems too high: http://support.microsoft.com/kb/969722

like image 83
David Neale Avatar answered Oct 25 '22 12:10

David Neale


As a general principle, you have to define what you mean by the number of users online.

For example, Sessions usually last for a predefined duration, such as 30 minutes. Depending on how long you expect users to be on your site, the duration of a session could be largely attributed to idle time when the user is not on your site.

In general you want people that have been online in the last n minutes. Sessions give you this statistic for one period of time (the configured session expiry), but there are many other time measures that would potentially be more relevant.

like image 1
Geoff Avatar answered Oct 25 '22 11:10

Geoff


One way to accomplish this is to simply have the IIS logs shove their data in a table in your database instead of the local file system. This is pretty easy to configure at the web server level.

Then you could easily graph that and show usage throughout the day, current, weekly, etc.

Of course, if you have a highly trafficked site, then this would result in a tremendous amount of data collected.

like image 1
NotMe Avatar answered Oct 25 '22 13:10

NotMe