public static class AzureDiagnostics
{
public static void InitializeAzureDiagnostics()
{
// do not run this code if we're not running in the cloud.
if (!Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)
return;
// Enabled the capture of partial crash dumps
Microsoft.WindowsAzure.Diagnostics.CrashDumps.EnableCollection(false);
// configure and start the diagnostics
DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();
AddPerformanceCounters(dmc);
AddLogs(dmc);
AddSystemEventLog(dmc);
AddInfrastructureLogs(dmc);
DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);
}
private static void AddInfrastructureLogs(DiagnosticMonitorConfiguration dmc)
{
dmc.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
dmc.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10.0);
}
private static void AddSystemEventLog(DiagnosticMonitorConfiguration dmc)
{
// Add event collection from the Windows Event Log
dmc.WindowsEventLog.DataSources.Add("System!*");
dmc.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
dmc.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);
}
private static void AddLogs(DiagnosticMonitorConfiguration dmc)
{
dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(10);
dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
}
private static void AddPerformanceCounters(DiagnosticMonitorConfiguration dmc)
{
List<string> counters = new List<string>();
counters.Add(@"\Processor(_Total)\% Processor Time");
counters.Add(@"\Memory\Available Mbytes");
counters.Add(@"\TCPv4\Connections Established");
counters.Add(@"\ASP.NET Applications(__Total__)\Requests/Sec");
// These network interfaces removed - not that interesting for now
//counters.Add(@"\Network Interface(*)\Bytes Received/sec");
//counters.Add(@"\Network Interface(*)\Bytes Sent/sec");
foreach (string counter in counters)
{
PerformanceCounterConfiguration counterConfig = new PerformanceCounterConfiguration();
counterConfig.CounterSpecifier = counter;
counterConfig.SampleRate = TimeSpan.FromSeconds(10);
dmc.PerformanceCounters.DataSources.Add(counterConfig);
}
dmc.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(5.0);
}
}
No comments:
Post a Comment