诊断数据需要很长时间才能记录在 Windows Azure 中

发布于 2024-11-28 00:12:40 字数 5158 浏览 1 评论 0原文

我编写了一小段代码,通过单击不同的按钮,将收集不同类型的日志记录数据。但是,当我运行这段代码时,通过服务器资源管理器检查时通常不会反映记录的数据,即使记录了这些数据,也可以在很长一段时间(15-20 分钟)后查看。我在编写这段代码时是否犯了任何错误。该段代码如下:

    DiagnosticMonitorConfiguration diagMonitorConfiguration;
    RoleInstanceDiagnosticManager roleInstanceDiagnosticManager;
    protected void Page_Load(object sender, EventArgs e)
    {


        // Get the default initial configuration for DiagnosticMonitor.
        diagMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();

        // Configures the transfer period for basic windows azure logs 
        diagMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(10);

        // Configures the log type to be Verbose
        diagMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        // Start the diagnostics monitor
        //DiagnosticMonitor.Start(CloudStorageAccount.DevelopmentStorageAccount, diagConfig);

        //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);

        //DiagnosticMonitorTraceListener tmpListener = new DiagnosticMonitorTraceListener();
        //System.Diagnostics.Trace.Listeners.Add(tmpListener);
    }

    // Used to trace custom warning messages
    protected void btnWarning_Click(object sender, EventArgs e)
    {
        // tracing user message as a warning
        System.Diagnostics.Trace.TraceWarning("WARNING ENCOUNTERED :" + TextBoxName.Text);
    }

    // tracing custom error messages 
    protected void btnError_Click(object sender, EventArgs e)
    {
        // To log the user message as an error
        .......TraceError("ERROR ENCOUNTERED :" + TextBoxName.Text);
    }

    // tracing custom information messages
    protected void btnInformation_Click(object sender, EventArgs e)
    {
        // To log the user message as mere information
        .........TraceInformation("INFORMATION SENT :" + TextBoxName.Text);
    }

    // used to enable diagnostic infrastructure logs to be collected
    protected void btnEnableInfrastructure_Click(object sender, EventArgs e)
    {
        // configuring the type and transfer period for the Infrastructure logs
        diagMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = some filter;
        diagMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = SOME TIME PERIOD            
        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);

    }

    // used to enable crash dumps for the application
    protected void btnEnableCrashDumps_Click(object sender, EventArgs e)
    {
        //enabling crash dumps
        CrashDumps.EnableCollection(true);

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }

    // used to enable the collection windows event logs
    protected void btnEnableEventLogs_Click(object sender, EventArgs e)
    {
        //Configuring the Windows Event logs
        diagMonitorConfiguration.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        // two types of events, application and system data are logged
        diagMonitorConfiguration.WindowsEventLog.DataSources.Add("some source");

        // the time interval is configured as 5 seconds
        diagMonitorConfiguration.WindowsEventLog.ScheduledTransferPeriod = some time period;

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }

    protected void btnEnablePerfCounters_Click(object sender, EventArgs e)
    {

        // configuring the performance counter data to be collected. processor time is collected
        diagMonitorConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
        {
            THE REQD PARAMETERS
        });

        // similarly available memory data is also logged
        diagMonitorConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
        {
            THE REQD PARAMETERS
        });

        // the scheduled time transfer is configured to 5seconds
        diagMonitorConfiguration.PerformanceCounters.ScheduledTransferPeriod = some time period;

        //DiagnosticMonitor.Start(CloudStorageAccount.DevelopmentStorageAccount, diagConfig);  USED PREVIOUSLY

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }
}

I've written a small piece of code whereby on different button click different types of logging data would be collected. However, when i run the piece of code, usualy the logged data is not reflected when checked through the server explorer and even if they are logged, they can be viewed after a long period of time(15-20 mins). Is there any mistake that i've commited while writing this piece of code. The piece of code is given below::

    DiagnosticMonitorConfiguration diagMonitorConfiguration;
    RoleInstanceDiagnosticManager roleInstanceDiagnosticManager;
    protected void Page_Load(object sender, EventArgs e)
    {


        // Get the default initial configuration for DiagnosticMonitor.
        diagMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration();

        // Configures the transfer period for basic windows azure logs 
        diagMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromSeconds(10);

        // Configures the log type to be Verbose
        diagMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        // Start the diagnostics monitor
        //DiagnosticMonitor.Start(CloudStorageAccount.DevelopmentStorageAccount, diagConfig);

        //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));

        CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
        roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);

        //DiagnosticMonitorTraceListener tmpListener = new DiagnosticMonitorTraceListener();
        //System.Diagnostics.Trace.Listeners.Add(tmpListener);
    }

    // Used to trace custom warning messages
    protected void btnWarning_Click(object sender, EventArgs e)
    {
        // tracing user message as a warning
        System.Diagnostics.Trace.TraceWarning("WARNING ENCOUNTERED :" + TextBoxName.Text);
    }

    // tracing custom error messages 
    protected void btnError_Click(object sender, EventArgs e)
    {
        // To log the user message as an error
        .......TraceError("ERROR ENCOUNTERED :" + TextBoxName.Text);
    }

    // tracing custom information messages
    protected void btnInformation_Click(object sender, EventArgs e)
    {
        // To log the user message as mere information
        .........TraceInformation("INFORMATION SENT :" + TextBoxName.Text);
    }

    // used to enable diagnostic infrastructure logs to be collected
    protected void btnEnableInfrastructure_Click(object sender, EventArgs e)
    {
        // configuring the type and transfer period for the Infrastructure logs
        diagMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = some filter;
        diagMonitorConfiguration.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = SOME TIME PERIOD            
        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);

    }

    // used to enable crash dumps for the application
    protected void btnEnableCrashDumps_Click(object sender, EventArgs e)
    {
        //enabling crash dumps
        CrashDumps.EnableCollection(true);

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }

    // used to enable the collection windows event logs
    protected void btnEnableEventLogs_Click(object sender, EventArgs e)
    {
        //Configuring the Windows Event logs
        diagMonitorConfiguration.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        // two types of events, application and system data are logged
        diagMonitorConfiguration.WindowsEventLog.DataSources.Add("some source");

        // the time interval is configured as 5 seconds
        diagMonitorConfiguration.WindowsEventLog.ScheduledTransferPeriod = some time period;

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }

    protected void btnEnablePerfCounters_Click(object sender, EventArgs e)
    {

        // configuring the performance counter data to be collected. processor time is collected
        diagMonitorConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
        {
            THE REQD PARAMETERS
        });

        // similarly available memory data is also logged
        diagMonitorConfiguration.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration()
        {
            THE REQD PARAMETERS
        });

        // the scheduled time transfer is configured to 5seconds
        diagMonitorConfiguration.PerformanceCounters.ScheduledTransferPeriod = some time period;

        //DiagnosticMonitor.Start(CloudStorageAccount.DevelopmentStorageAccount, diagConfig);  USED PREVIOUSLY

        // Update the configuration setting for the diagnostic manager
        roleInstanceDiagnosticManager.SetCurrentConfiguration(diagConfig);
        Thread.Sleep(5000);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生来就爱笑 2024-12-05 00:12:40

IIRC,1 分钟似乎是最短的传输时间。完全不确定如果将其设置为较小的值会发生什么。您可以检查生成的控制文件(在 wad-control 容器中)并查看实际设置的传输速率。请记住,这是一个异步过程(记录、本地缓冲,然后传输)。如果您想要实时的东西,您需要调整跟踪侦听器以直接记录到表或 blob(或使用服务总线跟踪)。 查看调试培训工具包了解如何完成此操作。

IIRC, 1 min seems to be the minimum transfer time. Not sure entirely what happens if you set it to something smaller. You can check the resulting control file (in the wad-control container) and see what the transfer rate is actually set to. Keep in mind this is an async process (log, buffer locally, then transfer). If you want something realtime you need to adapt the tracelistener to log directly to table or blobs (or use Service Bus tracing). Check the training kit on debugging for how this can be done.

听闻余生 2024-12-05 00:12:40

根据 文档

ScheduledTransferPeriod 属性用于设置传输频率
数据缓冲区将本地日志数据传输到持久存储。经过
默认情况下,没有为任何数据缓冲区设置此属性以防止
无意的存储成本。

您为此属性设置的值将四舍五入到最接近的值
分钟。因此,您可以指定的最短传输周期为 1
分钟。

As per the docs:

The ScheduledTransferPeriod property is used to set how frequently a
data buffer will transfer local logging data to persistent storage. By
default, this property is not set for any data buffer to prevent
unintentional storage costs.

The value you set for this property will be rounded up to the nearest
minute. Therefore, the minimum transfer period you can specify is 1
minute.

雪落纷纷 2024-12-05 00:12:40

不能肯定地说,但您多次调用 SetCurrentConfiguration()。上次我检查过,你只能调用一次。我不知道多次调用它会看到什么观察到的行为。我真的建议将所有诊断配置代码聚合到一个位置,也许在 global.asax 中,而不是分散在多个按钮处理程序中。

Can't say for sure, but you have multiple calls to SetCurrentConfiguration(). Last time I checked, you could only call this once. I have no idea what observed behavior you'll see by calling it multiple times. I'd really suggest aggregating all your diagnostics configuration code into one place, maybe in global.asax, and not scattered across several button handlers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文