示例#1
0
        /// <summary>
        /// Initialize method is called after all configuration properties have been loaded from the configuration.
        /// </summary>
        /// <param name="configuration">TelemetryConfiguration passed to the module.</param>
        public void Initialize(TelemetryConfiguration configuration)
        {
            if (!this.IsInitialized)
            {
                lock (this.moduleInitializationLock)
                {
                    if (!this.IsInitialized)
                    {
                        QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent(
                            this.QuickPulseServiceEndpoint,
                            this.DisableFullTelemetryItems,
                            this.DisableTopCpuProcesses,
                            this.AuthenticationApiKey);

                        QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration...");
                        ValidateConfiguration(configuration);
                        this.config = configuration;

                        QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members...");
                        this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager();

                        this.performanceCollector = this.performanceCollector ?? PerformanceCounterUtility.GetPerformanceCollector();

                        this.timeProvider    = this.timeProvider ?? new Clock();
                        this.topCpuCollector = this.topCpuCollector
                                               ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib()));
                        this.timings = this.timings ?? QuickPulseTimings.Default;

                        CollectionConfigurationError[] errors;
                        this.collectionConfiguration = new CollectionConfiguration(
                            new CollectionConfigurationInfo()
                        {
                            ETag = string.Empty
                        },
                            out errors,
                            this.timeProvider);
                        this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(this.collectionConfiguration);

                        this.InitializeServiceClient(configuration);

                        this.stateManager = new QuickPulseCollectionStateManager(
                            this.ServiceClient,
                            this.timeProvider,
                            this.timings,
                            this.OnStartCollection,
                            this.OnStopCollection,
                            this.OnSubmitSamples,
                            this.OnReturnFailedSamples,
                            this.OnUpdatedConfiguration,
                            this.OnUpdatedServiceEndpoint);

                        this.CreateStateThread();

                        this.IsInitialized = true;
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="QuickPulseTelemetryModule"/> class. Internal constructor for unit tests only.
 /// </summary>
 /// <param name="collectionTimeSlotManager">Collection time slot manager.</param>
 /// <param name="dataAccumulatorManager">Data hub to sink QuickPulse data to.</param>
 /// <param name="serviceClient">QPS service client.</param>
 /// <param name="performanceCollector">Performance counter collector.</param>
 /// <param name="topCpuCollector">Top N CPU collector.</param>
 /// <param name="timings">Timings for the module.</param>
 internal QuickPulseTelemetryModule(
     QuickPulseCollectionTimeSlotManager collectionTimeSlotManager,
     QuickPulseDataAccumulatorManager dataAccumulatorManager,
     IQuickPulseServiceClient serviceClient,
     IPerformanceCollector performanceCollector,
     IQuickPulseTopCpuCollector topCpuCollector,
     QuickPulseTimings timings)
     : this()
 {
     this.collectionTimeSlotManager = collectionTimeSlotManager;
     this.dataAccumulatorManager    = dataAccumulatorManager;
     this.ServiceClient             = serviceClient;
     this.performanceCollector      = performanceCollector;
     this.topCpuCollector           = topCpuCollector;
     this.timings = timings;
 }
        /// <summary>
        /// Initialize method is called after all configuration properties have been loaded from the configuration.
        /// </summary>
        /// <param name="configuration">TelemetryConfiguration passed to the module.</param>
        public void Initialize(TelemetryConfiguration configuration)
        {
            if (!this.isInitialized)
            {
                lock (this.lockObject)
                {
                    if (!this.isInitialized)
                    {
                        QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent(
                            this.QuickPulseServiceEndpoint,
                            this.DisableFullTelemetryItems,
                            this.DisableTopCpuProcesses);

                        QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration...");
                        this.ValidateConfiguration(configuration);
                        this.config = configuration;

                        QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members...");
                        this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager();
                        this.dataAccumulatorManager    = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager();
                        this.performanceCollector      = this.performanceCollector ??
                                                         (PerformanceCounterUtility.IsWebAppRunningInAzure() ? (IPerformanceCollector) new WebAppPerformanceCollector() : (IPerformanceCollector) new StandardPerformanceCollector());
                        this.timeProvider    = this.timeProvider ?? new Clock();
                        this.topCpuCollector = this.topCpuCollector
                                               ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib()));
                        this.timings = timings ?? QuickPulseTimings.Default;

                        this.InitializeServiceClient(configuration);

                        this.stateManager = new QuickPulseCollectionStateManager(
                            this.serviceClient,
                            this.timeProvider,
                            this.timings,
                            this.OnStartCollection,
                            this.OnStopCollection,
                            this.OnSubmitSamples,
                            this.OnReturnFailedSamples);

                        this.CreateStateThread();

                        this.isInitialized = true;
                    }
                }
            }
        }