

Navigator : Home > Tutorials > Performance Tutorials > ...
Windows performance monitoring in ASP.NET(VB)
This tutorial will show you how to use ASP.NET and VB to monitor Windows performance, e.g. performance counter, threads and processes.
Using the namespace of System.Diagnostics to get the data from Windows performance counter...
Imports System Imports System.Net Imports System.Diagnostics |
At first declare three PerformanceCounter instances, define the category and counters in performance monitor
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.
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
Dim objMemperf As New PerformanceCounter("Memory", "Available Bytes") Dim objProcperf As New PerformanceCounter("System", "Processes") Dim objComperf As 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 Then
For Each objPer In PerformanceCounterCategory.GetCategories
ListBox1.Items.Add(New ListItem(objPer.CategoryName)) Next End If End Sub |
The front page of Default.aspx
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
<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:
Imports System.Diagnostics Imports System.Web
Partial Class _Default
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objMemperf As New PerformanceCounter("Memory", "Available Bytes") Dim objProcperf As New PerformanceCounter("System", "Processes") Dim objComperf As New PerformanceCounter("System", "Threads") Dim objPer As New PerformanceCounterCategory Label1.Text = String.Format("{0:#,###}", objMemperf.NextValue()) & "Byte" Label2.Text = objProcperf.NextValue().ToString() Label3.Text = objComperf.NextValue().ToString() If Page.IsPostBack = False Then
For Each objPer In PerformanceCounterCategory.GetCategories
ListBox1.Items.Add(New ListItem(objPer.CategoryName)) Next End If End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!