private void GetPerformanceCounterConfiguration()
        {
            // Figure out if performance counter collection is enabled. By default
            // it is enabled and the 'IsEnabled' setting must be explicitly
            // specified to disable it.
            this.perfCounterConfig.IsEnabled = this.configReader.GetUnencryptedConfigValue(
                PerformanceCounterSectionName,
                IsEnabledParamName,
                true);
            if (this.perfCounterConfig.IsEnabled)
            {
                // Get the sampling interval
                this.perfCounterConfig.SamplingInterval = TimeSpan.FromSeconds(this.configReader.GetUnencryptedConfigValue(
                                                                                   PerformanceCounterSectionName,
                                                                                   SamplingIntervalInSecondsParamName,
                                                                                   (int)PerformanceCounterCommon.DefaultSamplingInterval.TotalSeconds));

                // Get the counter paths
                string counterListAsString = this.configReader.GetUnencryptedConfigValue(
                    PerformanceCounterSectionName,
                    CounterPathsParamName,
                    string.Empty);

                if (string.IsNullOrEmpty(counterListAsString))
                {
                    counterListAsString = PerformanceCounterCommon.LabelDefault;
                }

                PerformanceCounterCommon.ParseCounterList(counterListAsString, out this.perfCounterConfig.CounterPaths);

                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Performance counter data collection is enabled. Sampling interval: {0}.",
                    this.perfCounterConfig.SamplingInterval);
            }
            else
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Performance counter data collection has been disabled via the {0} parameter in the {1} section of the cluster manifest.",
                    IsEnabledParamName,
                    PerformanceCounterSectionName);
            }
        }
Exemplo n.º 2
0
        internal static bool StartCollection(SettingsOverridesTypeSection[] fabricSettings, FabricDeploymentSpecification deploymentSpecification)
        {
            if (!StopDataCollector())
            {
                return(false);
            }

            if (!DeleteDataCollector())
            {
                return(false);
            }

            var samplingInterval                 = PerformanceCounterCommon.DefaultSamplingInterval;
            HashSet <string> counters            = null;
            int    maxFileSizeInMB               = PerformanceCounterCommon.MaxPerformanceCountersBinaryFileSizeInMB;
            var    newFileCreationInterval       = PerformanceCounterCommon.NewPerfCounterBinaryFileCreationInterval;
            string outputFolderPath              = deploymentSpecification.GetPerformanceCountersBinaryFolder();
            string outputFileNamePrefix          = CounterFileNamePrefix;
            bool   includeMachineNameInOuputFile = false;
            bool   enableCircularTraceSession    = FabricEnvironment.GetEnableCircularTraceSession();

            SettingsOverridesTypeSection manifestSection = fabricSettings.FirstOrDefault(section => section.Name.Equals(Constants.SectionNames.PerformanceCounterLocalStore, StringComparison.OrdinalIgnoreCase));

            if (manifestSection != null)
            {
                var isEnabledParameter = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(System.Fabric.FabricValidatorConstants.ParameterNames.IsEnabled, StringComparison.OrdinalIgnoreCase));
                if (isEnabledParameter != null)
                {
                    bool isEnabled = bool.Parse(isEnabledParameter.Value);
                    if (!isEnabled)
                    {
                        DeployerTrace.WriteInfo(
                            "Performance counter collection is not enabled because parameter {0} in section {1} is set to false.",
                            System.Fabric.FabricValidatorConstants.ParameterNames.IsEnabled,
                            Constants.SectionNames.PerformanceCounterLocalStore);
                        return(true);
                    }
                }

                var samplingIntervalSecondsParameter = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(Constants.ParameterNames.SamplingIntervalInSeconds, StringComparison.OrdinalIgnoreCase));
                if (samplingIntervalSecondsParameter != null)
                {
                    samplingInterval = TimeSpan.FromSeconds(int.Parse(samplingIntervalSecondsParameter.Value, CultureInfo.InvariantCulture));
                }

                var countersParameter = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(System.Fabric.FabricValidatorConstants.ParameterNames.Counters, StringComparison.OrdinalIgnoreCase));
                if (countersParameter != null)
                {
                    PerformanceCounterCommon.ParseCounterList(countersParameter.Value, out counters);
                }

                var maxFileSizeInMBParameter = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(Constants.ParameterNames.MaxCounterBinaryFileSizeInMB, StringComparison.OrdinalIgnoreCase));
                if (maxFileSizeInMBParameter != null)
                {
                    maxFileSizeInMB = int.Parse(maxFileSizeInMBParameter.Value, CultureInfo.InvariantCulture);
                }

                var newFileCreationIntervalMinutesParameter = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(System.Fabric.FabricValidatorConstants.ParameterNames.NewCounterBinaryFileCreationIntervalMinutes, StringComparison.OrdinalIgnoreCase));
                if (newFileCreationIntervalMinutesParameter != null)
                {
                    newFileCreationInterval = TimeSpan.FromMinutes(int.Parse(newFileCreationIntervalMinutesParameter.Value, CultureInfo.InvariantCulture));
                }

                var testOnlyCounterFilePath = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(System.Fabric.FabricValidatorConstants.ParameterNames.TestOnlyCounterFilePath, StringComparison.OrdinalIgnoreCase));
                if (testOnlyCounterFilePath != null)
                {
                    outputFolderPath = testOnlyCounterFilePath.Value;
                }

                var testOnlyCounterFileNamePrefix = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(System.Fabric.FabricValidatorConstants.ParameterNames.TestOnlyCounterFileNamePrefix, StringComparison.OrdinalIgnoreCase));
                if (testOnlyCounterFileNamePrefix != null)
                {
                    outputFileNamePrefix = testOnlyCounterFileNamePrefix.Value;
                }

                var testOnlyIncludeMachineNameInCounterFileName = manifestSection.Parameter.FirstOrDefault(param => param.Name.Equals(Constants.ParameterNames.TestOnlyIncludeMachineNameInCounterFileName, StringComparison.OrdinalIgnoreCase));
                if (testOnlyIncludeMachineNameInCounterFileName != null)
                {
                    includeMachineNameInOuputFile = bool.Parse(testOnlyIncludeMachineNameInCounterFileName.Value);
                }
            }

            if (counters == null)
            {
                PerformanceCounterCommon.ParseCounterList(PerformanceCounterCommon.LabelDefault, out counters);
            }

            DeployerTrace.WriteInfo("Performance counter sampling interval: {0} seconds.", samplingInterval);

            if (!StartCollectionForCounterSet(
                    counters,
                    outputFolderPath,
                    outputFileNamePrefix,
                    includeMachineNameInOuputFile,
                    (int)samplingInterval.TotalSeconds,
                    maxFileSizeInMB,
                    (int)newFileCreationInterval.TotalMinutes,
                    enableCircularTraceSession))
            {
                return(false);
            }

            return(true);
        }