Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Performance - Windows performance monitoring in ASP.NET(C#)
Windows performance monitoring in ASP.NET(C#)


ASP.NET Performance Tutorial

This tutorial will show you how to use ASP.NET and C# to monitor Windows performance, e.g. performance counter, threads and processes.

Untitled Document

Download the Full Working Version of this Project written with Visual Studio.NET C# 2005 Here!

Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

Using the namespace of System.Diagnostics to get the data from Windows performance counter...

using System;
using System.Net;
using System.Diagnostics;

At first declare three PerformanceCounter instances, define the category and counters in performance monitor

Then display the values obtained in different Labels. Label1 is for displaying the available memory, Lable2 is for the current processes numbers, while Lable3 is used for the total processes

By the looping of PerformanceCounterCategory.GetCategories method to go through all available categories

PerformanceCounter objMemperf = new PerformanceCounter("Memory","Available Bytes");
PerformanceCounter objProcperf = new PerformanceCounter("System", "Processes");
PerformanceCounter objComperf = new PerformanceCounter("System", "Threads");

Label1.Text = string.Format("{0:#,###}", objMemperf.NextValue()) + "Byte";
Label2.Text = objProcperf.NextValue().ToString();
Label3.Text = objComperf.NextValue().ToString();

if (!Page.IsPostBack)
{
foreach(PerformanceCounterCategory objPer in PerformanceCounterCategory.GetCategories())
{
ListBox1.Items.Add(new ListItem(objPer.CategoryName));
}
}

The front page of Default.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Using Performance Counters</title>
</head>
<body>
<form id="form1" runat="server">
<h1>Web Server Stats</h1>
<i>These stats were taken as of <%=DateTime.Now.ToLongDateString() %> at <%=DateTime.Now.ToLongTimeString()%>....</i>
<br />
<br />
<b>Available:</b><asp:Label ID="Label1" runat="server" Width="251px"></asp:Label>
<br />
<b>
<br />
Tatol Processes:</b>
<asp:Label ID="Label2" runat="server" Width="247px"></asp:Label>
<br />
<br />
<b>Total Threding:</b><asp:Label ID="Label3" runat="server" Width="254px"></asp:Label>
      <br />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="38px" Width="368px"></asp:ListBox><br />
<br />
<br />
<br />
</form>
</body>
</html>

The whole code behind front page:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Diagnostics;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PerformanceCounter objMemperf = new PerformanceCounter("Memory","Available Bytes");
PerformanceCounter objProcperf = new PerformanceCounter("System", "Processes");
PerformanceCounter objComperf = new PerformanceCounter("System", "Threads");

Label1.Text = string.Format("{0:#,###}", objMemperf.NextValue()) + "Byte";
Label2.Text = objProcperf.NextValue().ToString();
Label3.Text = objComperf.NextValue().ToString();

if (!Page.IsPostBack)
{
foreach(PerformanceCounterCategory objPer in PerformanceCounterCategory.GetCategories())
{
ListBox1.Items.Add(new ListItem(objPer.CategoryName));
}
}
}

protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{

}
}

Download the Full Working Version of this Project written with Visual Studio.NET C# 2005 Here!

Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!







 
  Developer Resources







Server Intellect Rocks