Пример #1
0
        /// <summary>
        /// Invoke the middleware.
        /// </summary>
        public async Task Invoke(IDictionary <string, object> environment)
        {
            long elapsed = 0;
            var  timer   = OkanshiTimer.StartNew(x => elapsed = x);
            await next.Invoke(environment);

            timer.Stop();
            var tags = EmptyTagList;

            if (options.AddStatusCodeTag)
            {
                object responseCode;
                var    found = environment.TryGetValue("owin.ResponseStatusCode", out responseCode);
                if (found)
                {
                    tags.Add(new Tag("responseCode", responseCode.ToString()));
                }
            }

            tags.Add(new Tag("path", environment["owin.RequestPath"].ToString()));
            tags.Add(new Tag("method", environment["owin.RequestMethod"].ToString()));
            var basicTimer = OkanshiMonitor.BasicTimer(options.MetricName, tags.ToArray());

            basicTimer.Register(elapsed);
        }
Пример #2
0
        public void Timer_calls_the_callback_with_elapsed_milliseconds()
        {
            var elapsedMilliseconds = 0L;
            var timer = new OkanshiTimer(x => elapsedMilliseconds = x);

            timer.Start();
            Thread.Sleep(500);
            timer.Stop();

            elapsedMilliseconds.Should().BeInRange(400, 700);
        }
Пример #3
0
 public OkanshiTimerTest()
 {
     _timer = new OkanshiTimer(x => {}, () => _stopwatch);
 }