Example #1
0
        public async Task Invoke(HttpContext context)
        {
            if (Options.MetricsEndpointEnabled && Options.MetricsEndpoint.IsPresent() && Options.MetricsEndpoint == context.Request.Path)
            {
                Logger.MiddlewareExecuting(GetType());

                var metricsData = Metrics.Advanced.Data.ReadData();

                var json = _serializer.Serialize(metricsData);

                await WriteResponseAsync(context, json, MetricsMimeType);

                Logger.MiddlewareExecuted(GetType());

                return;
            }

            await _next(context);
        }
Example #2
0
        // ReSharper disable UnusedMember.Global
        public async Task Invoke(HttpContext context)
        // ReSharper restore UnusedMember.Global
        {
            if (Options.MetricsEndpointEnabled && Options.MetricsEndpoint.IsPresent() && Options.MetricsEndpoint == context.Request.Path)
            {
                Logger.MiddlewareExecuting(GetType());

                var metricsData = Metrics.Snapshot.Get();

                var json = _serializer.Serialize(metricsData);

                await WriteResponseAsync(context, json, MetricsMimeType);

                Logger.MiddlewareExecuted(GetType());

                return;
            }

            await _next(context);
        }
        public async Task Invoke(IDictionary <string, object> environment)
        {
            var requestPath = environment["owin.RequestPath"] as string;

            if (Options.MetricsEndpointEnabled && Options.MetricsEndpoint.IsPresent() && Options.MetricsEndpoint == requestPath)
            {
                Logger.MiddlewareExecuting(GetType());

                var metricsData = Metrics.Snapshot.Get();

                var json = _serializer.Serialize(metricsData);

                await WriteResponseAsync(environment, json, MetricsMimeType);

                Logger.MiddlewareExecuted(GetType());

                return;
            }

            await Next(environment);
        }
        public Task WriteAsync(HttpContext context, MetricsDataValueSource metricsData, CancellationToken token = default(CancellationToken))
        {
            var json = _serializer.Serialize(metricsData);

            return(context.Response.WriteAsync(json, token));
        }