public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; XmlConfigurator.Configure(); ILog log = LogManager.GetLogger(typeof(WorkerRole)); string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString)); RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id); DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration(); config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D); config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined; config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Warning; config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D); config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D); roleInstanceDiagnosticManager.SetCurrentConfiguration(config); PhotoTaskManager.Instance.Start(); RenderTaskManager.Instance.Start(); ProfileTaskManager.Instance.Start(); StatUpdate.Instance.Start(); return(base.OnStart()); }
public override bool OnStart() { string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"; RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = CloudAccountDiagnosticMonitorExtensions.CreateRoleInstanceDiagnosticManager(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString), RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id); DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration(); // should never be null, but this is a fallback in case it is. I recommend removing this in a production // deployment if (null == config) { config = DiagnosticMonitor.GetDefaultInitialConfiguration(); } config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(15); config.Logs.ScheduledTransferLogLevelFilter = Microsoft.WindowsAzure.Diagnostics.LogLevel.Undefined; config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = Microsoft.WindowsAzure.Diagnostics.LogLevel.Warning; config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(15); config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(15); roleInstanceDiagnosticManager.SetCurrentConfiguration(config); System.Diagnostics.Trace.TraceInformation("Diagnostics Running"); #region Setup CloudStorageAccount Configuration Setting Publisher // This code sets up a handler to update CloudStorageAccount instances when their corresponding // configuration settings change in the service configuration file. RoleEnvironment.Changed += (sender, arg) => { var key = CloudConfigurationManager.GetSetting(arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>().ToString()); if (arg.Changes.OfType <RoleEnvironmentConfigurationSettingChange>() .Any((change) => (change.ConfigurationSettingName == key.ToString()))) { // The corresponding configuration setting has changed, propagate the value RoleEnvironment.GetConfigurationSettingValue(key.ToString()); // { // In this case, the change to the storage account credentials in the // service configuration is significant enough that the role needs to be // recycled in order to use the latest settings. (for example, the // endpoint has changed) RoleEnvironment.RequestRecycle(); //} } }; //}); #endregion return(base.OnStart()); }
public override bool OnStart() { CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => { configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)); }); string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"; CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString)); RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id); DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration(); config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D); config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined; config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Warning; config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D); config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D); roleInstanceDiagnosticManager.SetCurrentConfiguration(config); return(base.OnStart()); }
/// <summary>Windows Azure診断(Windows Azure Diagnostics)関連の設定</summary> private void ConfigureDiagnostics() { // Windows Azure診断(Windows Azure Diagnostics)情報出力用のストレージ アカウント取得 string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"; //// ストレージ アカウントの初期化 //CloudStorageAccount cloudStorageAccount = // CloudStorageAccount.Parse( // RoleEnvironment.GetConfigurationSettingValue(wadConnectionString)); //// RoleInstance診断管理の初期化(ロールに対する診断の有効化) //RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = // cloudStorageAccount.CreateRoleInstanceDiagnosticManager( // RoleEnvironment.DeploymentId, // RoleEnvironment.CurrentRoleInstance.Role.Name, // RoleEnvironment.CurrentRoleInstance.Id); var storageConnectionString = RoleEnvironment.GetConfigurationSettingValue( wadConnectionString); var deploymentDiagnosticManager = new DeploymentDiagnosticManager( storageConnectionString, RoleEnvironment.DeploymentId); RoleInstanceDiagnosticManager roleInstanceDiagnosticManager = deploymentDiagnosticManager.GetRoleInstanceDiagnosticManager( RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id); // RoleInstance診断管理からコンフィグを取得する。 // ・基本的にはデフォルト設定を利用する。 // ・RoleEnvironment.Changedイベント ハンドラを仕掛ける場合はカレント設定を利用する。 DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration(); // roleInstanceDiagnosticManager.GetCurrentConfiguration(); #region Windows Azure診断(Windows Azure Diagnostics)APIを使用した設定開始 #region インフラストラクチャ ログ(診断モニタ自体のログ) // 転送レベルおよび転送間隔を設定 config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Undefined; // 要検討 config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromSeconds(15); // 要検討 #endregion // 出力先のTableストレージ名:WADDiagnosticInfrastructureLogsTable #region イベント ログの設定 // 取得するイベント ソースを設定 config.WindowsEventLog.DataSources.Add("Application!*"); config.WindowsEventLog.DataSources.Add("System!*"); // 転送レベルおよび転送間隔を設定 config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Undefined; // 要検討 config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(15); // 要検討 #endregion // 出力先のTableストレージ名:WADWindowsEventLogsTable #region パフォーマンス カウンタの転送設定 // カウンタ、サンプリング レートの指定 config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration() { CounterSpecifier = @"\Processor(_Total)\% Processor Time", SampleRate = TimeSpan.FromSeconds(10) }); config.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration() { CounterSpecifier = @"\Memory\Available Bytes", SampleRate = TimeSpan.FromSeconds(10) }); // 転送間隔を設定 config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(15); // 要検討 #endregion // 出力先のTableストレージ名:WADPerformanceCountersTable #region クラッシュ ダンプ転送の有効化 CrashDumps.EnableCollection(true); #endregion // 出力先のBlobストレージ コンテナ名:wad-crash-dumps #region IISログ、FREBログの転送設定(※ web.config への設定も必要) // IISログはデフォルトで取得が有効となっているため、Blobへの転送を指定するのみで収集が可能となる。 // FREB(Failed Request Trace log)ログについてはweb.config への設定も必要 #endregion // 出力先のBlobストレージ コンテナ名:wad-iis-logfiles、wad-iis-failedreqlogfiles #region トレース ログの設定(※ *.config への設定も必要) // 転送レベルおよび転送間隔を設定 config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined; // 要検討 config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1); // 要検討 #endregion // 出力先のTableストレージ名:WADLogsTable #region カスタム ログ(ローカル ストレージへの出力の場合) // 出力先ディレクトリ設定 DirectoryConfiguration dirConfig1 = new DirectoryConfiguration() { // 出力先Blobコンテナの指定 Container = "my-custom-logfiles1", // クォーターの設定(実際に使う量) DirectoryQuotaInMB = 100, }; // ローカル ストレージのパスを指定 //(ローカル ストレージの設定自体は、Visual Studioを使用し*.csdefに設定可能) LocalResource ls = RoleEnvironment.GetLocalResource("LogStorage"); dirConfig1.Path = ls.RootPath; // log4netに環境変数経由でパス情報(RootPath)を // 渡そうとしたがエミュレータ上でうまく動作せず断念。 // ローカル ストレージを転送元コレクションに追加 config.Directories.DataSources.Add(dirConfig1); // なお、ローカル ストレージのパスは、LocalResource.RootPathにて取得が可能である。 #endregion // 出力先のBlobストレージ コンテナ名:my-custom-logfiles1 #region カスタムログ(任意の出力先の場合) // 出力先ディレクトリ設定 DirectoryConfiguration dirConfig2 = new DirectoryConfiguration() { // 出力先Blobコンテナの指定 Container = "my-custom-logfiles2", // クォーターの設定(実際に使う量) DirectoryQuotaInMB = 100, }; // 任意のディレクトリを指定 string path = "c:\\logs"; dirConfig2.Path = path; // ディレクトリを転送元コレクションに追加 config.Directories.DataSources.Add(dirConfig2); // ディレクトリ セキュリティを取得 DirectorySecurity ds = Directory.GetAccessControl(path); // Everyone FullControlのアクセス ルールの生成 FileSystemAccessRule AccessRule = new FileSystemAccessRule( "Everyone", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); // ディレクトリ キュリティにアクセス ルールを追加 ds.AddAccessRule(AccessRule); // ディレクトリにディレクトリ セキュリティを反映 // ★ <Runtime executionContext="elevated"/>を「*.csdef」に記述。 Directory.SetAccessControl(path, ds); #endregion // 出力先のBlobストレージ コンテナ名:my-custom-logfiles2 // IISログ、カスタム ログ、クラッシュ ダンプなどで // 使用するディレクトリ バッファからBlobストレージへの転送間隔の指定 config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(15); #endregion // RoleInstance診断管理にコンフィグを設定 roleInstanceDiagnosticManager.SetCurrentConfiguration(config); // 診断の開始(エミュレータでは不要だが、実機では必要 DiagnosticMonitor.Start(wadConnectionString, config); // ローカル ストレージへのログ出力テスト path = Path.Combine(ls.RootPath, string.Format("test_{0}.txt", DateTime.Now.ToString("yyyyMMdd"))); // StreamWriterを開き、ログを出力 using (StreamWriter sw = new StreamWriter(path, true)) { sw.WriteLine("{0} : {1}", DateTime.UtcNow, "ローカル ストレージへのログ出力テスト"); sw.Close(); } }
private static void EnableCounters(int sampleRateInSeconds, int transferPeriodInSeconds, string[] counters, RoleInstanceDiagnosticManager ridmN) { DiagnosticMonitorConfiguration dmc = ridmN.GetCurrentConfiguration(); foreach (string counter in counters) { if (!string.IsNullOrWhiteSpace(counter)) { PerformanceCounterConfiguration pcc = new PerformanceCounterConfiguration(); pcc.CounterSpecifier = counter.Trim(); pcc.SampleRate = TimeSpan.FromSeconds(sampleRateInSeconds); dmc.PerformanceCounters.DataSources.Add(pcc); Trace.WriteLine(string.Format("Counter '{0}' Sample Rate {1} seconds", counter, sampleRateInSeconds)); } } dmc.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromSeconds(transferPeriodInSeconds); ridmN.SetCurrentConfiguration(dmc); }
private void ConfigureProfileStorage() { LocalResource profileStorage; try { profileStorage = RoleEnvironment.GetLocalResource("ProfileStorage"); } catch (RoleEnvironmentException e) { throw new InvalidOperationException("Local storage \"ProfileStorage\" not found.", e); } var ridm = new RoleInstanceDiagnosticManager( CloudConfigurationManager.GetSetting("AzurePerfTools.PowerShellWindowsService.ConnectionString"), RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id); var dmc = ridm.GetCurrentConfiguration() ?? DiagnosticMonitor.GetDefaultInitialConfiguration(); DirectoryConfiguration directoryConfig; directoryConfig = new DirectoryConfiguration() { Container = "profiles", Path = profileStorage.RootPath, //DirectoryQuotaInMB = 1000, }; dmc.Directories.DataSources.Add(directoryConfig); dmc.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0); ridm.SetCurrentConfiguration(dmc); }