How To Programmatically Configure AppFabric Monitoring Levels

The IIS Manager modules added by AppFabric provide a graphical interface for you to enable monitoring, configure the monitoring level, choose a tracking profile, and configure message logging and tracing features.   After you obtain this monitoring data, you can view it and work with it within the AppFabric Dashboard. The AppFabric Dashboard provides a centralized view of all monitoring data for your applications that include WCF and/or WF services.  

 

Most operations carried out by the AppFabric UI map to Windows PowerShell cmdlets. These Windows PowerShell calls are run by the AppFabric user interface and make changes to the underlying configuration files. This gives you the freedom to automate monitoring configuration or to manage monitoring configuration entirely from the Windows PowerShell console (command line).   You have the freedom to run cmdlets serially, pipe them together, or run them in a script file.

 

AppFabric monitoring uses event data to display rich troubleshooting data for unhealthy applications and status data for healthy applications.  WCF services emit analytic trace events, which are collected depending on the verbosity defined by the monitoring level. A WF service emits analytic trace events from the WCF communication layer and WF tracking events from the workflow. Monitoring levels provide a convenient way to configure WF and WCF service instrumentation. AppFabric provides a default set of monitoring levels that store different amounts of data for visibility into its applications. You can select the appropriate level of instrumentation based upon your requirements for troubleshooting or performance. Each level consists of the instrumentation events that are emitted by the applications and events. They are collected by the Event Collection service, and stored in the monitoring database. There  are five monitoring levels, in order of increasing verbosity: Off, Errors Only, Health Monitoring (default), End to End Monitoring, and Troubleshooting.

Configure the Monitoring Level Using Windows Powershell

To programmatically configure the monitoring levels, you will use the Windows PowerShell cmdlet Set-ASAppMonitoring. After you set the monitoring level, you can run Get-ASAppMonitoring at any time to check the currently configured level for the scope at which the cmdlet is executing. This cmdlet affects the following configuration file setting:

** **

<microsoft.applicationServer>

**   <monitoring>**

<default enabled="true" connectionStringName="ApplicationServerMonitoringConnectionString" monitoringLevel="HealthMonitoring" />

**  </monitoring>**

</microsoft.applicationServer>

 

You can also enable or disable monitoring in AppFabric by running the Start-ASAppMonitoring or Stop-ASAppMonitoring cmdlet, respectively. While these cmdlets don’t affect the monitoring level setting,

they are a quick way to turn monitoring on or off. 

** **

**      <microsoft.applicationServer>**

**       <monitoring>**

**        <default enabled="false" connectionStringName="ApplicationServerMonitoringConnectionString"      **

**         monitoringLevel="HealthMonitoring" />**

**       </monitoring>**

**      </microsoft.applicationServer>**

 

 

Here are the different syntaxes and parameters for the Set-ASAppMonitoring cmdlet used to set the monitoring level:

**
Set-ASAppMonitoring [-SiteName] <String> [-VirtualPath] <String> -MonitoringLevel [-Confirm] [-ConnectionStringName <String>]**

Set-ASAppMonitoring [-Uri] <Uri> -MonitoringLevel [-Confirm] [-ConnectionStringName <String>]

Set-ASAppMonitoring [-ApplicationObject] <ApplicationInfo> -MonitoringLevel [-Confirm] [-ConnectionStringName <String>]

**Set-ASAppMonitoring -MonitoringLevel [-Confirm] [-ConnectionStringName <String>] -Root **

 

Parameter Description

[-SiteName] <String> [[-VirtualPath] <String>]. [-Uri] <Uri>, -ApplicationObject <ApplicationInfo>, or -Root

Operational scope of the cmdlet

-MonitoringLevel

{<Custom> | <EndToEndMonitoring> | <ErrorsOnly> | <HealthMonitoring> | <Off> | <Troubleshooting>}

-Confirm

Option to confirm action or not

-ConnectionStringName <String>

Connection string to access specific monitoring database

 

 

Here are two examples of the Set-ASAppMonitoring cmdlet. The first example sets monitoring settings in the root Web.config file.  The second one sets settings at the application level for the MyWorkflowApp application.  Both of the scopes show the default HealthMonitoring level as the configured monitoring level.

 

Example 1

 

**PS C:\Windows\system32> Set-ASAppMonitoring -MonitoringLevel HealthMonitoring -Confirm -ConnectionStringName **

ApplicatinServerMonitoringConnectionString  -Root

 

ConnectionStringName : ApplicationServerMonitoringConnectionString

ConnectionString     : Data Source=MICROSO-XNMDH06;Initial Catalog=AppFabricMonitoringStore;Integrated Security=True

IsEnabled            : True

MonitoringLevel      : HealthMonitoring

ProviderId           : c651f5f6-1c0d-492e-8ae1-b4efd7c9d503

ProviderName         : System.Data.SqlClient

TrackingProfile      : HealthMonitoring Tracking Profile

SiteName             :

VirtualPath          :

 

 

Example 2

**
PS C:\Windows\system32> Set-ASAppMonitoring -Sitename "Default Web Site" -VirtualPath "/MyWorkflowApp"  -MonitoringLevel HealthMonitoring -ConnectionStringName  ApplicationServerMonitoringConnectionString**

 

ConnectionStringName : ApplicationServerMonitoringConnectionString

ConnectionString     : Data Source=MICROSO-XNMDH06;Initial Catalog=AppFabricMonitoringStore;Integrated Security=True

IsEnabled            : True

MonitoringLevel      : HealthMonitoring

ProviderId           : 0d163658-e838-4ade-adff-f0d8a8e20b52

ProviderName         : System.Data.SqlClient

TrackingProfile      : HealthMonitoring Tracking Profile

SiteName             : Default Web Site

VirtualPath          : /MyWorkflowApp

 

 

Here are some tips for running the SetASAppMonitoring AppFabric cmdlet:

  • Run Windows Powershell Modules (from Administrative Tools) with elevated administrator permissions. 
  • Run **Import-Module ApplicationServer ** to import the module containing all of the AppFabric cmdlets.
  • Run get-help Set-ASAppMonitoring to obtain the syntax of the cmdlet.

 

Configure the Monitoring Level from C# Code

You can also write .NET code by using the Windows Powershell SDK that invokes AppFabric cmdlets.  Your .NET project must reference the Windows PowerShell automation assembly located at C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0. Use this version even though it points to Version 1 (v1.0).   Also, if you will be running your image on an x64 platform, make sure you compile your project against "x64".  To do this you must manually create this target configuration in your Visual Studio project.

Here is some code you can use to programmatically set the monitoring level by using the Set-ASAppMonitoring cmdlet.  Note the ps.Command.Clear(); line – without it the call to Invoke for Set-ASAppMonitoring won’t work.

 

 

using System.Management.Automation;

              ...

 

PowerShell ps = PowerShell.Create();

ps.AddCommand("Import-Module", true).AddParameter("Name", "ApplicationServer");

ps.Invoke();

ps.Commands.Clear();

 

PowerShell cmd = ps.AddCommand("Set-ASAppMonitoring", true);

cmd.AddParameter("SiteName", "Default Web Site");

cmd.AddParameter("VirtualPath", "MortgageServices");

cmd.AddParameter("MonitoringLevel", "HealthMonitoring");

cmd.AddParameter("ConnectionStringName", "ApplicationServerMonitoringConnectionString");

Collection<PSObject> result = ps.Invoke();