Exemplo n.º 1
0
        public async Task Invoke(IDictionary <string, object> contextDict)
        {
            TimerMetrics.StartRequest();
            TimerMetrics.StartResponse();
            ++_activeRequests;

            _owinContext = new OwinContext(contextDict);

            await _next.Invoke(contextDict);

            --_activeRequests;
            _errors4xx = _owinContext.Response.StatusCode.ToString()[0] == '4' ? ++_errors4xx : _errors4xx;
            _errors5xx = _owinContext.Response.StatusCode.ToString()[0] == '5' ? ++_errors5xx : _errors5xx;

            RequestMetrics();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseMiddleware <MetricsMiddleware>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();

            app.Use(async(context, next) => {
                TimerMetrics.StopRequest();
                await next.Invoke();
            });
        }
Exemplo n.º 3
0
        private void RequestMetrics()
        {
            TimerMetrics.StopRequest();
            TimerMetrics.StopResponse();

            var dto = new RequestMetricsDTO
            {
                Client      = _client,
                Application = _application,
                Environment = _environment,
                UserCall    = _owinContext.Request.Headers.Get("UserId"),
                Endpoint    = _owinContext.Request.Path.Value,
                Method      = _owinContext.Request.Method,
                StatusCode  = _owinContext.Response.StatusCode,
                //
                RequestTime  = TimerMetrics.RequestTime,
                ResponseTime = TimerMetrics.ResponseTime,
            };


            SendRabbitMQQueue("RequestMetrics", dto);
        }
Exemplo n.º 4
0
 public void ResponseHandle()
 {
     ApplicationMetricsHandle(EnumRequestResponse.Response);
     TimerMetrics.StopRequest();
     RequestMetricsHandle();
 }
Exemplo n.º 5
0
 public void RequestHandle()
 {
     TimerMetrics.StartResponse();
     TimerMetrics.StartRequest();
     ApplicationMetricsHandle(EnumRequestResponse.Request);
 }