/// <summary>
        /// Load the page list box with the current set of configured performance counters.
        /// </summary>
        protected void LoadListBox()
        {
            try
            {
                this.ListBox1.Items.Clear();

                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(
                    WebRole.GetConfigurationSettingValue(WebRole.WADConnectionString));

                var roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
                    RoleEnvironment.DeploymentId,
                    RoleEnvironment.CurrentRoleInstance.Role.Name,
                    RoleEnvironment.CurrentRoleInstance.Id);

                var roleDiagnosticMonitorConfiguration = roleInstanceDiagnosticManager.GetCurrentConfiguration();
                var performanceCounterSources          = roleDiagnosticMonitorConfiguration.PerformanceCounters.DataSources;

                foreach (var configuration in performanceCounterSources)
                {
                    this.ListBox1.Items.Add(configuration.CounterSpecifier);
                }
            }
            catch (RoleEnvironmentException rex)
            {
                // The connection string was missing or invalid.
                System.Diagnostics.Trace.WriteLine("WebRole environment diagnostics error: " + rex.Message);
            }
            catch (InvalidOperationException iox)
            {
                // Parse of the connection string failed.
                System.Diagnostics.Trace.WriteLine("WebRole environment diagnostics error: " + iox.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// The page load event handler.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // Refresh page every few seconds.
            Response.AddHeader("Refresh", "30");

            this.LabelSampleRate.Text =
                WebRole.GetConfigurationSettingValue(WebRole.WebRoleSampleRateName);
            this.LabelTransferInterval.Text =
                WebRole.GetConfigurationSettingValue(WebRole.WebRolePeriodName);
        }
        /// <summary>
        /// Initializes static members of the PerformanceCountersDataSource class.
        /// </summary>
        static PerformanceCountersDataSource()
        {
            storageAccount = CloudStorageAccount.Parse(
                WebRole.GetConfigurationSettingValue(WebRole.WADConnectionString));

            CloudTableClient cloudTableClient = new CloudTableClient(
                storageAccount.TableEndpoint.ToString(),
                storageAccount.Credentials);

            serviceContext             = cloudTableClient.GetDataServiceContext();
            serviceContext.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1.0d));

            roleId = RoleEnvironment.CurrentRoleInstance.Id;
        }
        /// <summary>
        /// Updates the performance counter configuration based on the current list in ServiceConfiguration.cscfg.
        /// </summary>
        private static void ConfigureDiagnostics()
        {
            try
            {
                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(
                    WebRole.GetConfigurationSettingValue(WADConnectionString));

                var roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
                    RoleEnvironment.DeploymentId,
                    RoleEnvironment.CurrentRoleInstance.Role.Name,
                    RoleEnvironment.CurrentRoleInstance.Id);

                var roleDiagnosticMonitorConfiguration = roleInstanceDiagnosticManager.GetCurrentConfiguration();

                // Copy settings from configuration.
                double webRolePeriod;
                if (!double.TryParse(WebRole.GetConfigurationSettingValue(WebRolePeriodName), out webRolePeriod))
                {
                    Trace.WriteLine("WebRole environment diagnostics error: " + WebRolePeriodName + " parse failed.");

                    // Set the default to one minute.
                    webRolePeriod = 1d;
                }

                // Transfer diagnostic information once every webRolePeriod minutes.
                TimeSpan transferPeriod = TimeSpan.FromMinutes(webRolePeriod);
                roleDiagnosticMonitorConfiguration.PerformanceCounters.ScheduledTransferPeriod = transferPeriod;

                double webRoleSampleRate;
                if (!double.TryParse(WebRole.GetConfigurationSettingValue(WebRoleSampleRateName), out webRoleSampleRate))
                {
                    Trace.WriteLine("WebRole environment diagnostics error: " + WebRoleSampleRateName + " parse failed.");

                    // Set the default to ten seconds.
                    webRoleSampleRate = 10d;
                }

                // Remove original performance counters and add new set
                roleDiagnosticMonitorConfiguration.PerformanceCounters.DataSources.Clear();

                string   webRoleConfig            = WebRole.GetConfigurationSettingValue(WebRoleConfigName);
                string[] separators               = new string[] { ConfigSeparator };
                string[] webRoleCounterSpecifiers = webRoleConfig.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                foreach (string specifier in webRoleCounterSpecifiers)
                {
                    roleDiagnosticMonitorConfiguration.PerformanceCounters.DataSources.Add(
                        new PerformanceCounterConfiguration()
                    {
                        CounterSpecifier = specifier,
                        SampleRate       = TimeSpan.FromSeconds(webRoleSampleRate)
                    });

                    Trace.WriteLine("WebRole performance counter added: " + specifier);
                }

                roleInstanceDiagnosticManager.SetCurrentConfiguration(roleDiagnosticMonitorConfiguration);
            }
            catch (RoleEnvironmentException rex)
            {
                // The connection string was missing.
                Trace.WriteLine("WebRole environment diagnostics error: " + rex.Message);
            }
            catch (InvalidOperationException iox)
            {
                // Parse of the connection string failed.
                Trace.WriteLine("WebRole environment diagnostics error: " + iox.Message);
            }
        }