Compartir a través de


Uploading Crash Dump from Azure VM to Windows Azure Storage using Diagnostics Monitor Agent

Using
Windows Azure SDK 1.4
you can use the following code in Web Role or
Worker Role to Add :

 

         public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12;

           //We need to get default initial configuration
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
            //Windows Azure Logs. Table: WADLogsTable
            config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
            config.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(5);
            //Performance counters. Table: WADPerformanceCountersTable
            config.PerformanceCounters.DataSources.Add(
                new PerformanceCounterConfiguration
                   {
                        CounterSpecifier = @"\Processor(*)\*",
                        SampleRate = TimeSpan.FromSeconds(1)
                    }
                );
            config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromSeconds(5);
            //You can add more performance counter using the link below:
            // - https://blogs.msdn.com/b/avkashchauhan/archive/2011/04/01/list-of-performance-counters-for-windows-azure-web-roles.aspx?wa=wsignin1.0

            //Windows Azure Diagnostic Infrastructure Logs. Table: WADDiagnosticInfrastructureLogsTable
            config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromSeconds(5);

            //Windows Event Logs. Table: WADWindowsEventLogsTable
            config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
            config.WindowsEventLog.DataSources.Add("Application!*");
            config.WindowsEventLog.DataSources.Add("System!*");
            config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromSeconds(5);
            //Crash Dumps. Blob. Container: wad-crash-dumps
            CrashDumps.EnableCollection(true);

            //Custom Error Logs
            var localResource = RoleEnvironment.GetLocalResource("ErrorStorageFolder"); // ErrorStroageFolder is the Local Storage you will have to add with You Role
            var directoryConfiguration = new DirectoryConfiguration
                                 {
                                      Container = "wad-custom-log-container",
                                      DirectoryQuotaInMB = localResource.MaximumSizeInMegabytes,
                                     Path = localResource.RootPath
                                 };
            config.Directories.DataSources.Add(directoryConfiguration);
            config.Directories.BufferQuotaInMB = 1024;
            config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);//for crash dumps and custom error log
           // Based  on above code, you can verify that you have setup dump data transfer time to 1 minutes.
            //Start with new configuration
            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);

           Thread.Sleep(10000);
           //Adding 10 seconds time so crash dumps can be uploaded. You can find a suitable time depend on your test to upload the crash dumps. 

            return base.OnStart();
}

 

 

Verification on
Windows Azure VM:

You can
verify that infrastructure log are created in Windows Azure VM at location
below:

C:\Resources\directory\<Deployment_ID>.<Role_Name>.<StorageName>\

The
crash dumps will be located at folder bellow:

C:\Resources\directory\<Deployment_ID>.<Role_Name>.<StorageName>
\CrashDumps

You can
also look at the Monitoring Host configuration file for the role and verify the
transfer time is set as below:

<Directories>

     
<BufferQuotaInMB>1</BufferQuotaInMB>

     
<ScheduledTransferPeriodInMinutes>1</ScheduledTransferPeriodInMinutes>

     
<Subscriptions>

       
<DirectoryConfiguration>

         
<Path>********** Role Path **************** </Path>

         
<Container>wad-crash-dumps</Container>

         
<DirectoryQuotaInMB>1024</DirectoryQuotaInMB>

       
</DirectoryConfiguration>

     
</Subscriptions>

   
</Directories>

Further Analysis:

Once the crash will occur the
role will die and upload will be scheduled during next role startup. Based on
above, the crash dump will be uploaded next time your role starts up, and it
will take some time for the uploading. If your role only runs for a short time
after the crash, then Diagnostics may not have enough time for the
uploading. That's why we have added Thread.Sleep() in the above code to give
enough time to upload the crash dumps when created.

Here is how it works:

1-
Role starts and then
crash happens due to any reason during start

2-
The crash dump was
created immediately

3-
This crash cause
application to exit

4-
When App Agent
starts the role again the crash dump is being uploaded however if time is very
less to upload and the upload action is broken and crash dumps cannot be
uploaded

5-
Adding some sleep
time in the same thread solves this crash dump upload issue