How to read diagnostics from Windows Azure
One of the first questions I am being asked whenever I present windows azure is: How to read monitoring and diagnostics.
Well Windows azure is quite powerful concerning diagnostics. Every role can contain a diagnostic monitor agent that can be started using: DiagnosticMonitor.Start . The agent collects diagnostic information according to the configuration you supply. The information must be persisted somewhere for us to be able to watch it. So someone needs to tell the agent to save its information to azure storage.
There are two ways to do that.
1.Configure a persistence period for each type of information. The agent will persist the data in the rate you define.
2. Call the agent from the outside using REST and instruct the agent to persist on demand.
In this code snippet I demonstrate how to configure the persistence rate and the information to be collected.
// Get default initial configuration.
var diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
// Capture complete crash dumps
Microsoft.WindowsAzure.Diagnostics.CrashDumps.EnableCollection(true);
//Set filter and sampling persistence rate. diagConfig.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error;
diagConfig.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
diagConfig.Directories.ScheduledTransferPeriod =
TimeSpan.FromMinutes(1.0);
diagConfig.Logs.ScheduledTransferPeriod =
TimeSpan.FromMinutes(1.0);
diagConfig.WindowsEventLog.ScheduledTransferPeriod =
TimeSpan.FromMinutes(1.0);
diagConfig.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
// Adding performance counters to the default diagnostic configuration
PerformanceCounterConfiguration procTimeConfig = new PerformanceCounterConfiguration();
procTimeConfig.CounterSpecifier = @"\Processor(*)\% Processor Time";
procTimeConfig.SampleRate = System.TimeSpan.FromSeconds(1.0);
diagConfig.PerformanceCounters.DataSources.Add(procTimeConfig);
// Adding performance counters to the default diagnostic configuration
PerformanceCounterConfiguration diskBytesConfig = new PerformanceCounterConfiguration();
diskBytesConfig.CounterSpecifier = @"\LogicalDisk(*)\Disk Bytes/sec";
diskBytesConfig.SampleRate = System.TimeSpan.FromSeconds(1.0);
diagConfig.PerformanceCounters.DataSources.Add(diskBytesConfig);
PerformanceCounterConfiguration workingSetConfig = new PerformanceCounterConfiguration();
workingSetConfig.CounterSpecifier = @"\Process(" +
System.Diagnostics.Process.GetCurrentProcess().ProcessName +
@")\Working Set";
workingSetConfig.SampleRate = System.TimeSpan.FromSeconds(1.0);
diagConfig.PerformanceCounters.DataSources.Add(workingSetConfig);
// Buffer event logs locally
diagConfig.WindowsEventLog.DataSources.Add("System!*");
diagConfig.WindowsEventLog.DataSources.Add("Application!*");
// Start the diagnostic monitor with the modified configuration.
DiagnosticMonitor.Start("DiagnosticsConnectionString", diagConfig);
The information is persisted into storage blobs and tables depending on the information type. The compete listing of storage locations can be found here. The tables are created automatically so you do not have to worry about creating them.
To look at the storage I use a tool called: Azure Storage Explorer
Here I present Windows Event Logs:
