So I thought it would be cool, to create a page for my wife's web site, that would let me know how many people are on her site at any given time. This will be useful to know when it's OK to upload new code that would bring the site down. Don't want to upset our users! Since her site is on a shared hosting environment I don't have physical access to the box. So I created an admin page on the site that prints out the number of users on the site using this code:
//using System.Diagnostics;PerformanceCounter PC;PC = new PerformanceCounter("Web Service", "Current Anonymous Users", true)PC.InstanceName = "";Response.Write("Current Anonymous Users: " + PC.NextValue().ToString());
The first argument in creating the new PerformanceCounter is the Category of the Performance Counter (SQL Server, Browser, Server, Memory, Processor, etc.) The next argument is the item for that category (Current connections, Active Sessions, Current FTP Connections, etc.) The two things to know when doing this are to: 1.> Know the instance of the item that you want to monitor. The instance name is the name of the site in IIS, or if you were looking at CPU utilization, the processor, etc. You can find this data by looking in Perfmon, or by asking your service provider. 2.> On your PerfomanceCounter object PC in this case, call the NextValue() method to get the current value of the counter.
This is a pretty simple example of accessing the performance counters intrinsic to the OS.
Remember Me
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, John Batdorf
E-mail