/// <summary> /// Initialize method is called after all configuration properties have been loaded from the configuration. /// </summary> public void Initialize(TelemetryConfiguration configuration) { try { if (!this.IsInitialized) { EventCounterCollectorEventSource.Log.ModuleIsBeingInitializedEvent(this.Counters?.Count ?? 0); if (this.Counters.Count <= 0) { EventCounterCollectorEventSource.Log.EventCounterCollectorNoCounterConfigured(); } this.client = new TelemetryClient(configuration); this.client.Context.GetInternalContext().SdkVersion = SdkVersionUtils.GetSdkVersion("evtc:"); this.eventCounterListener = new EventCounterListener(this.client, this.Counters, this.refreshInternalInSecs, this.UseEventSourceNameAsMetricsNamespace); this.IsInitialized = true; EventCounterCollectorEventSource.Log.ModuleInitializedSuccess(); } } catch (Exception ex) { EventCounterCollectorEventSource.Log.EventCounterCollectorError("Initialization", ex.Message); } }
public void EventCounterListenerGetsMetricsTest() { var options = new MetricsEndpointOptions(); var stats = new TestOpenTelemetryMetrics(); var factory = stats.Factory; var processor = stats.Processor; using var listener = new EventCounterListener(stats, new MetricsObserverOptions()); Task.Delay(2000).Wait(); factory.CollectAllMetrics(); foreach (var metric in _longMetrics) { var summary = processor.GetMetricByName <long>(metric); Assert.NotNull(summary); Assert.True(summary.Count > 0); } foreach (var metric in _doubleMetrics) { var summary = processor.GetMetricByName <double>(metric); Assert.NotNull(summary); Assert.True(summary.Count > 0); } }
public void EventCounterListenerGetsMetricsTest() { var options = new MetricsEndpointOptions(); var stats = new TestOpenTelemetryMetrics(); var factory = stats.Factory; var processor = stats.Processor; using var listener = new EventCounterListener(stats); Task.Delay(2000).Wait(); factory.CollectAllMetrics(); var longMetrics = new string[] { "System.Runtime.alloc-rate", "System.Runtime.gen-2-gc-count", "System.Runtime.threadpool-completed-items-count", "System.Runtime.monitor-lock-contention-count", "System.Runtime.gen-1-gc-count", "System.Runtime.gen-0-gc-count", "System.Runtime.exception-count" }; var doubleMetrics = new string[] { "System.Runtime.time-in-gc", "System.Runtime.threadpool-thread-count", "System.Runtime.gen-1-size", "System.Runtime.threadpool-queue-length", "System.Runtime.gen-2-size", "System.Runtime.gc-heap-size", "System.Runtime.assembly-count", "System.Runtime.gen-0-size", "System.Runtime.cpu-usage", "System.Runtime.active-timer-count", "System.Runtime.loh-size", "System.Runtime.working-set" }; foreach (var metric in longMetrics) { var summary = processor.GetMetricByName <long>(metric); Assert.NotNull(summary); Assert.True(summary.Count > 0); } foreach (var metric in doubleMetrics) { var summary = processor.GetMetricByName <double>(metric); Assert.NotNull(summary); Assert.True(summary.Count > 0); } }
static void Main(string[] args) { // Create a new event listener using (var listener = new EventCounterListener()) { string connectionString = "Data Source=localhost; Integrated Security=true"; for (int i = 0; i < 50; i++) { // Open a connection SqlConnection cnn = new SqlConnection(connectionString); cnn.Open(); // wait for sampling interval happens System.Threading.Thread.Sleep(500); } } }
public void EventCounterListenerGetsMetricsWithExclusionsTest() { var options = new MetricsEndpointOptions(); var stats = new TestOpenTelemetryMetrics(); var factory = stats.Factory; var processor = stats.Processor; var exclusions = new List <string> { "alloc-rate", "threadpool-completed-items-count", "gen-1-gc-count", "gen-1-size" }; using var listener = new EventCounterListener(stats, new MetricsObserverOptions { ExcludedMetrics = exclusions }); Task.Delay(2000).Wait(); factory.CollectAllMetrics(); foreach (var metric in _longMetrics) { var summary = processor.GetMetricByName <long>(metric); if (!exclusions.Contains(metric.Replace("System.Runtime.", string.Empty))) { Assert.NotNull(summary); Assert.True(summary.Count > 0); } else { Assert.Null(summary); } } foreach (var metric in _doubleMetrics) { var summary = processor.GetMetricByName <double>(metric); if (!exclusions.Contains(metric.Replace("System.Runtime.", string.Empty))) { Assert.NotNull(summary); Assert.True(summary.Count > 0); } else { Assert.Null(summary); } } }