Initializing Windows Azure Diagnostic: Part 2



In my previous article I explained how to initialize the Windows Azure diagnostic monitor. Now we will see how to collect various diagnostic data. I am defining a connection string for the role. For that right click on the role and click on properties. Now from the connection tab you can add a configuration string.

Azure4.gif

  1. Collecting data from event logs

    Open the Role entry point class. Add the following code to the OnStart() function:

    var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
    config.WindowsEventLog.DataSources.Add("System!*");
    config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Warning;
    config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);

    DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

    So, first you need to get a DiagnosticMonitorConfiguration object. Then you can add a channel to the datasource. You can add multiple channels. Windows Azure cannot log a security channel. You can define a log level filter, so that only those logs are transferred. You have to define a schedule transfer period, so that after that time span, logs are transferred to the account you specified in the configuration. Now start the diagnostic monitor with the connection and new configuration.

  2. Collect data from Performance Counters

    Open the Role entry point class. Add the following code to the OnStart() function:

    var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
    config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
    {
        CounterSpecifier = @"\Processor(_Total)\% Processor Time",
        SampleRate = TimeSpan.FromMinutes(1.0),
    });
    config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5.0);
    DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

    Here I have defined a performance counter which takes a sample for processor time in every minute. You can add multiple performance counters in the data source. And then every 5 minutes transfer the log to the Azure account defined in the connection string.

  3. Collect data from IIS logs

    IIS logs are collected only for a web role because worker and VM roles don't run under IIS.

    To enable IIS logging add the following code to the web.config.
     

    <tracing>

        <traceFailedRequests>

          <add path="*">

            <traceAreas>

              <add provider="ASP" verbosity="Verbose" />

              <add provider="ASPNET" areas="Infrastructure, Module, Page, AppServices" verbosity="Verbose" />

              <add provider="ISAPI Extension" verbosity="Verbose" />

              <add provider="WWW Server"

    areas="Authentication, Security, Filter, StaticFile, CGI, Compression, Cache, RequestNotifications, Module"

                   verbosity="Verbose" />

            </traceAreas>

            <failureDefinitions statusCodes="400-599" />

          </add>

        </traceFailedRequests>

        </tracing>

    After adding this code IIS logs are automatically logged. No additional API calls are required.

  4. Collect data from crash dumps

    In the role entry point class add the following code:

    Microsoft.WindowsAzure.Diagnostics.CrashDumps.EnableCollection(true);


Pass true for enabling complete crash dump data, or false for partial crash dump data.


Similar Articles