public void Run(IConfigurationRoot configuration) { var sink = ChooseSink(); var metricsWriterSettings = configuration.GetSection("MetricsWriter").Get <MetricsWriterSettings>(); var metricsCollectorSettings = configuration.GetSection("MetricsCollector").Get <MetricsCollectorSettings>(); if (sink is IDatabasePlugin databasePlugin) { var databaseConnectionSettings = configuration.GetSection("Database:Connection").Get <DatabaseConnectionSettings>(); var databaseTablesSettings = configuration.GetSection("Database:Tables").Get <DatabaseTablesSettings>(); databasePlugin.Initialize(databaseConnectionSettings, databaseTablesSettings, metricsWriterSettings); } using (var metrics = new MetricsCollector(sink, metricsCollectorSettings)) { Console.WriteLine("Press some keys; enter to exit"); metrics.RegisterThresholds("latency", new int[] { 0, 50, 75, 100, 1000, 2000, 10000 }); var stopwatch = new Stopwatch(); char key; do { stopwatch.Start(); key = Console.ReadKey(true).KeyChar; stopwatch.Stop(); metrics.IncrementCounter(key.ToString()); metrics.IncrementBucket("latency", stopwatch.ElapsedMilliseconds); metrics.Event(key.ToString()); // letters a-z: lowercase is start of interval, uppercase is end. if (key >= 'a' && key <= 'z') { metrics.StartInterval("session", key.ToString()); } else if (key >= 'A' && key <= 'Z') { metrics.EndInterval("session", key.ToString().ToLower()); } stopwatch.Reset(); } while (key != '\r' && key != '\n'); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public void HistogramTimingTest() { var sink = new DictionarySink(); var clock = new DummyClock("12:00:00.000"); var windowSize = TimeSpan.FromSeconds(1); var flushInterval = TimeSpan.FromSeconds(1); var metrics = new MetricsCollector(sink, clock, windowSize, flushInterval, false); metrics.RegisterThresholds("h", new[] { 0, 10, 20 }); metrics.RegisterThresholds("g", new[] { 30, 40 }); var window1From = clock.Current.RoundDown(windowSize); var window1To = window1From + windowSize; metrics.IncrementBucket("h", 0); clock.Advance(windowSize); sink.Buckets[new Metric("h", window1From, window1From + windowSize)][(0, 10)].Should().Be(1);
public void IncrementBucket() => metrics.IncrementBucket(names[random.Next() % 50], random.Next() % 100);