internal void PerformanceCollectorSanityTest(IPerformanceCollector collector, string counter, string categoryName, string counterName, string instanceName) { const int CounterCount = 3; for (int i = 0; i < CounterCount; i++) { string error; collector.RegisterCounter( counter, null, true, out error, false); } var results = collector.Collect().ToList(); Assert.AreEqual(CounterCount, results.Count); foreach (var result in results) { var value = result.Item2; Assert.AreEqual(categoryName, result.Item1.PerformanceCounter.CategoryName); Assert.AreEqual(counterName, result.Item1.PerformanceCounter.CounterName); if (instanceName != null) { Assert.AreEqual(instanceName, result.Item1.PerformanceCounter.InstanceName); } Assert.IsTrue(value >= 0 && value <= 100); } }
internal void PerformanceCollectorNormalizedCpuTest(IPerformanceCollector collector) { string error = null; collector.RegisterCounter( @"\Process(??APP_WIN32_PROC??)\% Processor Time Normalized", null, true, out error, false); collector.RegisterCounter( @"\Process(??APP_WIN32_PROC??)\% Processor Time", null, true, out error, false); var results = collector.Collect().ToList(); Assert.AreEqual(2, results.Count); Assert.AreEqual("Process", results[0].Item1.PerformanceCounter.CategoryName); Assert.AreEqual("% Processor Time Normalized", results[0].Item1.PerformanceCounter.CounterName); Assert.AreEqual("Process", results[1].Item1.PerformanceCounter.CategoryName); Assert.AreEqual("% Processor Time", results[1].Item1.PerformanceCounter.CounterName); Assert.AreEqual(results[0].Item1.PerformanceCounter.InstanceName, results[1].Item1.PerformanceCounter.InstanceName); Assert.IsTrue(results[0].Item2 >= 0 && results[0].Item2 <= 100); }
/// <summary> /// Initializes a new instance of the <see cref="PerformanceCollectorModule"/> class. /// </summary> public PerformanceCollectorModule() { this.Counters = new List <PerformanceCounterCollectionRequest>(); this.collector = this.collector ?? (PerformanceCounterUtility.IsWebAppRunningInAzure() ? (IPerformanceCollector) new WebAppPerformanceCollector() : (IPerformanceCollector) new StandardPerformanceCollector()); }
internal void PerformanceCollectorBadStateTest(IPerformanceCollector collector) { var counters = new PerformanceCounter[] { new PerformanceCounter("Processor", "% Processor Time", "_Total123blabla"), new PerformanceCounter("Processor", "% Processor Time", "_Total") }; foreach (var pc in counters) { try { string error = null; collector.RegisterCounter( PerformanceCounterUtility.FormatPerformanceCounter(pc), null, true, out error, false); } catch (Exception) { } } Assert.IsTrue(collector.PerformanceCounters.First().IsInBadState); Assert.IsFalse(collector.PerformanceCounters.Last().IsInBadState); }
internal void PerformanceCollectorRefreshCountersTest(IPerformanceCollector collector) { var counters = new PerformanceCounter[] { new PerformanceCounter("Processor", "% Processor Time", "_Total123blabla"), new PerformanceCounter("Processor", "% Processor Time", "_Total"), new PerformanceCounter("Processor", "% Processor Time", "_Total123afadfdsdf"), }; foreach (var pc in counters) { try { string error = null; collector.RegisterCounter( PerformanceCounterUtility.FormatPerformanceCounter(pc), null, true, out error, false); } catch (Exception) { } } collector.RefreshCounters(); // All bad state counters are removed and added later through register counter, and as a result, the order of the performance coutners is changed. Assert.AreEqual(collector.PerformanceCounters.First().InstanceName, "_Total"); Assert.AreEqual(collector.PerformanceCounters.Last().InstanceName, "_Total123afadfdsdf"); }
private static PerformanceCollectorModule CreatePerformanceCollectionModule(IPerformanceCollector collector, List <PerformanceCounterCollectionRequest> customCounterList = null) { var module = new PerformanceCollectorModule(collector); if (customCounterList != null) { customCounterList.ForEach(module.Counters.Add); } // set test-friendly timings var privateObject = new PrivateObject(module); privateObject.SetField("collectionPeriod", TimeSpan.FromMilliseconds(10)); // build agent is unable to handle performance collection, so don't put any placeholders here for unit testing privateObject.SetField( "defaultCounters", new List <string>() { @"\DefaultCategory1\DefaultCounter1", @"\DefaultCategory2(Instance2)\DefaultCounter2" }); return(module); }
internal void PerformanceCollectorRefreshCountersTest(IPerformanceCollector collector) { var counters = new PerformanceCounter[] { new PerformanceCounter("Processor", "% Processor Time", "_Total123blabla"), new PerformanceCounter("Processor", "% Processor Time", "_Total"), new PerformanceCounter("Processor", "% Processor Time", "_Total123afadfdsdf"), }; foreach (var pc in counters) { try { string error = null; collector.RegisterCounter( PerformanceCounterUtility.FormatPerformanceCounter(pc), null, true, out error, false); } catch (Exception) { } } collector.RefreshCounters(); // All bad state counters are removed and added later through register counter, and as a result, the order of the performance coutners is changed. Assert.AreEqual(collector.PerformanceCounters.First().PerformanceCounter.InstanceName, "_Total"); Assert.AreEqual(collector.PerformanceCounters.Last().PerformanceCounter.InstanceName, "_Total123afadfdsdf"); }
internal void PerformanceCollectorSanityTest(IPerformanceCollector collector, string counter, string categoryName, string counterName, string instanceName) { const int CounterCount = 3; for (int i = 0; i < CounterCount; i++) { string error = null; collector.RegisterCounter( counter, null, true, out error, false); } var results = collector.Collect().ToList(); Assert.AreEqual(CounterCount, results.Count); foreach (var result in results) { var value = result.Item2; Assert.AreEqual(categoryName, result.Item1.CategoryName); Assert.AreEqual(counterName, result.Item1.CounterName); if (instanceName != null) { Assert.AreEqual(instanceName, result.Item1.InstanceName); } Assert.IsTrue(value >= 0 && value <= 100); } }
/// <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; } } } }
static MainWindow() { var counterCreationDatas = new[] { new CounterCreationData(COUNTER_NAME, "Help", PerformanceCounterType.NumberOfItems64), new CounterCreationData(COUNTER2_NAME, "Help", PerformanceCounterType.RateOfCountsPerSecond64) }; _performanceCollector = PerformanceCollector.Create("_Temp1", "test", counterCreationDatas); }
/// <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="timings">Timings for the module.</param> internal QuickPulseTelemetryModule( QuickPulseCollectionTimeSlotManager collectionTimeSlotManager, QuickPulseDataAccumulatorManager dataAccumulatorManager, IQuickPulseServiceClient serviceClient, IPerformanceCollector performanceCollector, QuickPulseTimings timings) : this() { this.collectionTimeSlotManager = collectionTimeSlotManager; this.dataAccumulatorManager = dataAccumulatorManager; this.serviceClient = serviceClient; this.performanceCollector = performanceCollector; this.timings = timings; }
private static PerformanceCollectorModule CreatePerformanceCollectionModule(IPerformanceCollector collector, List <PerformanceCounterCollectionRequest> customCounterList = null) { var module = new PerformanceCollectorModule(collector); if (customCounterList != null) { customCounterList.ForEach(module.Counters.Add); } module.CollectionPeriod = TimeSpan.FromMilliseconds(10); module.DefaultCounters.Add(new PerformanceCounterCollectionRequest(@"\DefaultCategory1\DefaultCounter1", @"\DefaultCategory1\DefaultCounter1")); module.DefaultCounters.Add(new PerformanceCounterCollectionRequest(@"\DefaultCategory2(Instance2)\DefaultCounter2", @"\DefaultCategory2(Instance2)\DefaultCounter2")); return(module); }
/// <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; } } } }
/// <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( string.Format( CultureInfo.InvariantCulture, "QuickPulseServiceEndpoint: '{0}', DisableFullTelemetryItems: '{1}'", this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems)); 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 ?? new PerformanceCollector(); this.timeProvider = this.timeProvider ?? new Clock(); 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; } } } }
/// <summary> /// Initializes a new instance of the <see cref="PerformanceCollectorModule"/> class. /// </summary> public PerformanceCollectorModule() { this.Counters = new List <PerformanceCounterCollectionRequest>(); this.collector = PerformanceCounterUtility.GetPerformanceCollector(); }
/// <summary> /// Initializes a new instance of the <see cref="PerformanceCollectorModule"/> class. /// </summary> /// <remarks>Unit tests only.</remarks> internal PerformanceCollectorModule(IPerformanceCollector collectorMock) : this() { this.collector = collectorMock; }
private static PerformanceCollectorModule CreatePerformanceCollectionModule(IPerformanceCollector collector, List<PerformanceCounterCollectionRequest> customCounterList = null) { var module = new PerformanceCollectorModule(collector); if (customCounterList != null) { customCounterList.ForEach(module.Counters.Add); } // set test-friendly timings var privateObject = new PrivateObject(module); privateObject.SetField("collectionPeriod", TimeSpan.FromMilliseconds(10)); // build agent is unable to handle performance collection, so don't put any placeholders here for unit testing privateObject.SetField( "defaultCounters", new List<string>() { @"\DefaultCategory1\DefaultCounter1", @"\DefaultCategory2(Instance2)\DefaultCounter2" }); return module; }
/// <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( string.Format( CultureInfo.InvariantCulture, "QuickPulseServiceEndpoint: '{0}', DisableFullTelemetryItems: '{1}'", this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems)); 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.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; } } } }
private static PerformanceCollectorModule CreatePerformanceCollectionModule(IPerformanceCollector collector, List<PerformanceCounterCollectionRequest> customCounterList = null) { var module = new PerformanceCollectorModule(collector); if (customCounterList != null) { customCounterList.ForEach(module.Counters.Add); } module.CollectionPeriod = TimeSpan.FromMilliseconds(10); module.DefaultCounters.Add(new PerformanceCounterCollectionRequest(@"\DefaultCategory1\DefaultCounter1", @"\DefaultCategory1\DefaultCounter1")); module.DefaultCounters.Add(new PerformanceCounterCollectionRequest(@"\DefaultCategory2(Instance2)\DefaultCounter2", @"\DefaultCategory2(Instance2)\DefaultCounter2")); return module; }
/// <summary> /// Initializes a new instance of the <see cref="PerformanceCollectorModule"/> class. /// </summary> public PerformanceCollectorModule() { this.Counters = new List<PerformanceCounterCollectionRequest>(); this.collector = this.collector ?? (PerformanceCounterUtility.IsWebAppRunningInAzure() ? (IPerformanceCollector)new WebAppPerformanceCollector() : (IPerformanceCollector)new StandardPerformanceCollector()); }