[英]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. 该站点在iis7上运行,我们正在使用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. 不需要历史记录,我只想知道现在有多少用户“在线”,并将其显示在页面本身上。
You can use Windows Performance counters for this (perfmon) 您可以为此使用Windows Performance计数器(性能)
ASP.NET Applications > Sessions Active counter. ASP.NET应用程序>会话活动计数器。
You can access these performance counters using the System.Diagnostics namespace. 您可以使用System.Diagnostics命名空间访问这些性能计数器。
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 我遇到了这个问题,因此如果计数器似乎过高,请看这里: http : //support.microsoft.com/kb/969722
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. 例如,会话通常持续预定义的持续时间,例如30分钟。 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. 通常,您希望最近n分钟内一直在线的人。 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. 会话会在一段时间内为您提供此统计信息(配置的会话到期),但是还有许多其他时间度量可能更相关。
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. 实现此目的的一种方法是简单地使IIS日志将其数据推入数据库中的表中,而不是将其推到本地文件系统中。 This is pretty easy to configure at the web server level. 这在Web服务器级别很容易配置。
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. 当然,如果您的网站流量很高,那么这将导致收集大量数据。
对于EPiServer网站,您可能需要查看Live Monitor: http : //www.episerver.com/add-on-store/episerver-live-monitor/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.