Skip to main content

Building Web Application for Monitoring (ASP.NET Web Events, WMI, Performance Counters)



Customizing Event Analysis:
After deployment to make the life of administrators easy, ASP.NET provides the following facilities:

* Monitor Live ASP.NET Application individually or across Web Farm.
* Diagnose an application that appears to be failing.
* Log events which are not exception but useful for investigation.

Ways to notify Administrator about the errors:
Through Event Log, E-Mail notification, Event stored in database.

Other helpful events could be:
1. Starting or Ending a Web Application
2. Successful and unsuccessful authentication attempts
3. ASP.NET errors
4. Custom Application Events
In ASP.NET All Errors and Failure Audits events are enabled.

Other ASP.NET Event Providers and Web Events are:

ASP.NET Event Provider:


Event Provider
Description
EventLogWebEventProvider
Writes Web event data to the Windows event log. By default, this provider is configured to write all errors to the Windows event log. Security operation errors are logged under the event name Failure Audits and all other errors are logged under the event name All Errors.
SqlWebEventProvider
Logs Web event data to a Microsoft SQL Server database. By default, this provider logs data to the SQL Server Express database in the Web application’s App_Data folder.
WmiWebEventProvider
Passes Web events to Windows Management Instrumentation (WMI), converting them to WMI events.
SimpleMailWebEventProvider and TemplatedMailWebEventProvider
Sends an e-mail message when Web events are raised.
TraceWebEventProvider
Passes event data to the ASP.NET page tracing system. You can use the events to debug an application and perform capacity and performance analysis.


 


To create Custom Event Providers inherit from WebEventProvider or BufferedWebEventProvider. For more details on Provider Visit:
http://msdn2.microsoft.com/en-us/ms228095.aspx




ASP.NET Web Events
 
Health monitoring process using WMI:





Configuring Health-Monitoring Events:
Health Monitoring is configured in web.config and have the following major elements:

<bufferModes>:Events may raise in a frequent manner causing web application to remain busy in Health-Monitoring. <bufferModes> allows Health-Monitoring Events to be processed and dispatched in batches.

<provider>: By default it contains EventLogProvider, LocalSqlServer, WmiWebEventProvider. SimpleMailWebEventProvider, TemplatedMailWebEventProvider can be also configured.

<profiles>: It defines how many times an event can occur in specified time. Default (prevents more than once in a minute) and Critical (See every event that occur) are available by default.

<rules>: Associates Events with EventProviders. By Default All Errors and FailureAudits à EventLogProvider.

<eventMappings>: Associates event name with the class that implements them. All Errors ß WebBaseEvent and Failure Audits ß WebFailureAuditEvent.


Sample
  <healthMonitoring heartbeatInterval="0" enabled="true">
    <bufferModes>
      <add name="Critical Notification"
      maxBufferSize="100"
      maxFlushSize="20"
      urgentFlushThreshold="1"
      regularFlushInterval="Infinite"
      urgentFlushInterval="00:01:00"
      maxBufferThreads="1" />
      <add name="Notification"
      maxBufferSize="300"
      maxFlushSize="20"
      urgentFlushThreshold="1"
      regularFlushInterval="Infinite"
      urgentFlushInterval="00:01:00"
      maxBufferThreads="1" />
    </bufferModes>
    <providers>
      <add
      name="EventLogProvider"
      type="System.Web.Management.EventLogWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
      <add
      ConnectionStringName="LocalSqlServer"
      maxEventDetailsLength="1073741823"
      buffer="false"
      bufferMode="Notification"
      name="SqlWebEventProvider"
      type="System.Web.Management.SqlWebEventProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" />
    </providers>

    <profiles>
      <add
      name="Default"
      minInstances="1"
      maxLimit="Infinite"
      minInterval="00:01:00"
      custom="" />
      <add
      name="Critical"
      minInstances="1"
      maxLimit="Infinite"
      minInterval="00:00:00"
      custom="" />
    </profiles>
    <rules>
      <add
      name="All Errors Default"
      eventName="All Errors" provider="EventLogProvider"
      profile="Default"
      minInstances="1"
      maxLimit="Infinite"
      minInterval="00:01:00"
      custom="" />
      <add
      name="Failure Audits Default"
      eventName="Failure Audits"
      provider="EventLogProvider"
      profile="Default"
      minInstances="1"
      maxLimit="Infinite"
      minInterval="00:01:00"
      custom="" />
    </rules>
    <eventMappings>
      <add
      name="All Events"
      type="System.Web.Management.WebBaseEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
      startEventCode="0"
      endEventCode="2147483647" />
      <add
      name="All Errors"
      type="System.Web.Management.WebBaseErrorEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
      startEventCode="0"
      endEventCode="2147483647" />
      <add
      name="All Audits"
      type="System.Web.Management.WebAuditEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
      startEventCode="0" endEventCode="2147483647" />
      <add
      name="Failure Audits"
      type="System.Web.Management.WebFailureAuditEvent, System.Web,Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
      startEventCode="0"
      endEventCode="2147483647" />
    </eventMappings>
  </healthMonitoring>

Providing Custom Performance Counters:
With .Net 2.0 Developers can easly add custom performance counter and to Update Performance data from within your code.

Monitoring Performace Counters:
First Create Performance Counter and provide it with useful data.

PerformanceCounter pc = new PerformanceCounter( “ASP.NET”, “Requests Queued”);
lblQueued.Text = pc.RawValue.ToString();

To view performance open performance Dialog from:
Administrative Tools | Performance

To Add Performace Counter from UI Go to Server Explorer, Expand the Node R.Click the “Performance Counter” And select New Category. Provide name and description. Click Add. Now Add counters to category.

It’s better to add Counters Programmaticlly during Setup.

Adding Custom Performance Counter Catogries:
Performance Counter can be added to Existing categories, It’s recommended to define a newer category specific to application.

To create a Performance Counter Category with a single counter:

PerformanceCounterCategory.Create(“CategoryName”, “CounterHelp”, PerformanceCounterCategoryType.MultiInstance, “CounterName”, “CounterHelp”);

To Add multiples counters to a single category Use CounterCreationDataCollection class.



Providing Performance Counter Data:
Performance Data is sampled over 400 Miliiseconds. Update the Performance counter data when changes occur.

To Update Data create Performance Counter as you are reading it but specify False for ReadOnly property.

PerformanceCounter pc = new PerformanceCounter( “MyAppCountries”, “Sales”, false);

Pc.RawValue = 7;
Pc.Decrement();
Pc.Increment();
Pc.IncrementBy(3);
Pc.DecrementBy(3);

Popular posts from this blog

Culture Information and Localization in .NET

Namespace: System.Globalization CultureInfo Class:                 It provides information like the Format of numbers and dates, Culture’s Calendar, Culture’s language and sublanguage (if applicable), Country and region of the culture. The Basic use of CultureInfo class is shown here: • How string Comparisons are performed • How Number Comparison & Formats are performed • Date Comparison and Formats. • How resources are retrieved and used. Cultures are grouped into three categories: Invariant Culture : It’s Culture Insensitive. It can be used to build some trial application. It can be also used to build an application with hard-coded expiry date that ignores cultures. But using it for every comparison will be incorrect and inappropriate. Neutral Culture : English(en), Frensh(fr), and Spanish(sp). A neutral culture is related to language but it’s not related to specific regi...

Concept of App Domain in .Net

Creating Application Domains: Application domain is just like process, provides separate memory space, and isolates from other code. But it’s quite light weight. It also provides the following advantages: 1-       Reliability : If a domain crashes, it can be unloaded. Hence doesn’t affect the other assemblies. 2-       Efficiency : Loading all assemblies in one domain can be cumbersome and can make the process heavy but Appdomains are efficient in this manner. Important properties of AppDomain: ApplicationIdentity , ApplicationTrust , BaseDirectory , CurrentDomain , DomainManager , DomainDirectory , Evidence , FriendlyName , ID , RelativeSearchPath , SetupInformation , ShadowCopyFiles . Important methods of AppDomain: ApplyPolicy , CreateCOMInstanceFrom , CreateDomain , CreateInstance (Assembly). To create an AppDomain: AppDomain adomain = AppDomain.CreateDomain(“D”); To execute an assembly:...

ASP.NET Working With Data-Bound Web Server Controls

Suppose we have: List<Car> vCars = new List<Car>(); There are three types of databound controls: Simple databound controls(List, AdRotater), Composite data bound controls(GridView, DetailsView, FormView that inherit from CompositeDataBoundControl), and Hierarchal data bound controls (TreeView, Menu).   DataBoundControl has a DataBind method that can be used when data is ready. It calls DataBind for child controls as well. Page.DataBind() will call DataBind for all child controls. Using DataSource Objects:                                       BaseDataBound control exposes DataSource property that accepts objects that implement IEnumerable , IListSource , IDataSource , or IHierarchalDataSource . DataSourceID accepts ID of SqlDataSource . If both specified Data...