Example #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;
                    }
                }
            }
        }
Example #2
0
 public void GetCollectorReturnsWebAppCollector()
 {
     try
     {
         Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "something");
         var actual = PerformanceCounterUtility.GetPerformanceCollector();
         Assert.AreEqual("WebAppPerformanceCollector", actual.GetType().Name);
     }
     finally
     {
         PerformanceCounterUtility.isAzureWebApp = null;
         Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", string.Empty);
         Task.Delay(1000).Wait();
     }
 }
Example #3
0
        public void GetCollectorReturnsCorrectCollector()
        {
            try
            {
                var actual = PerformanceCounterUtility.GetPerformanceCollector();
#if NETCOREAPP2_0
                Assert.AreEqual("StandardPerformanceCollector", actual.GetType().Name);
#else // NET452
                Assert.AreEqual("StandardPerformanceCollector", actual.GetType().Name);
#endif
            }
            finally
            {
                PerformanceCounterUtility.isAzureWebApp = null;
            }
        }
        public void GetCollectorReturnsXPlatformCollectorForNonWindows()
        {
#if NETCOREAPP2_0
            var original = PerformanceCounterUtility.IsWindows;
            try
            {
                PerformanceCounterUtility.IsWindows = false;
                var actual = PerformanceCounterUtility.GetPerformanceCollector();
                Assert.AreEqual("PerformanceCollectorXPlatform", actual.GetType().Name);
            }
            finally
            {
                PerformanceCounterUtility.IsWindows     = original;
                PerformanceCounterUtility.isAzureWebApp = null;
            }
#endif
        }
        public void GetCollectorReturnsXPlatformCollectorForWebAppForLinux()
        {
#if NETCOREAPP2_0
            var original = PerformanceCounterUtility.IsWindows;
            try
            {
                Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "something");
                PerformanceCounterUtility.IsWindows = false;
                var actual = PerformanceCounterUtility.GetPerformanceCollector();
                Assert.AreEqual("PerformanceCollectorXPlatform", actual.GetType().Name);
            }
            finally
            {
                PerformanceCounterUtility.IsWindows     = original;
                PerformanceCounterUtility.isAzureWebApp = null;
                Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", string.Empty);
                Task.Delay(1000).Wait();
            }
#endif
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PerformanceCollectorModule"/> class.
        /// </summary>
        public PerformanceCollectorModule()
        {
            this.Counters = new List <PerformanceCounterCollectionRequest>();

            this.collector = PerformanceCounterUtility.GetPerformanceCollector();
        }