public RequestTimerMiddleware(RequestDelegate next, MetricsOptions options, AspNetMetricsContext metricsContext) : base(options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _next = next; _requestTimer = metricsContext.Context.GetWebApplicationContext() .Timer("Web Requests", Unit.Requests); }
public PerRequestTimerMiddleware(RequestDelegate next, MetricsOptions options, AspNetMetricsContext metricsContext) : base(options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (metricsContext == null) { throw new ArgumentNullException(nameof(metricsContext)); } _next = next; _metricsContext = metricsContext; }
public HealthEndpointEndpointMiddleware(RequestDelegate next, MetricsOptions options, AspNetMetricsContext metricsContext) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (metricsContext == null) { throw new ArgumentNullException(nameof(metricsContext)); } _next = next; _options = options; _metricsContext = metricsContext; }
public static IApplicationBuilder UseMetrics(this IApplicationBuilder app, MetricsConfig config, Clock clock) { if (app == null) { throw new ArgumentNullException(nameof(app)); } // Verify if AddMetrics was done before calling UseMetrics // We use the MetricsMarkerService to make sure if all the services were added. MetricsServicesHelper.ThrowIfMetricsNotRegistered(app.ApplicationServices); var options = app.ApplicationServices.GetService <IOptions <MetricsOptions> >().Value; config.WithConfigExtension((ctx, hs) => { var metricsContext = new AspNetMetricsContext(ctx, hs, clock); // Metrics Endpoint Middleware app.Use(next => new MetricsEndpointMiddleware(next, options, metricsContext).Invoke); app.Use(next => new PingEndpointEndpointMiddleware(next, options).Invoke); app.Use(next => new HealthEndpointEndpointMiddleware(next, options, metricsContext).Invoke); app.Use(next => new MetricsEndpointTextEndpointMiddleware(next, options, metricsContext).Invoke); app.Use(next => new MetricsEndpointVisualizationEndpointMiddleware(next, options).Invoke); // Web Metrics Middleware app.Use(next => new ErrorRequestMeterMiddleware(next, options, metricsContext).Invoke); app.Use(next => new OAuth2ClientWebRequestMeterMiddleware(next, options, metricsContext).Invoke); app.Use(next => new PerRequestTimerMiddleware(next, options, metricsContext).Invoke); app.Use(next => new RequestTimerMiddleware(next, options, metricsContext).Invoke); app.Use(next => new ActiveRequestCounterEndpointMiddleware(next, options, metricsContext).Invoke); app.Use(next => new PostAndPutRequestSizeHistogramMiddleware(next, options, metricsContext).Invoke); }); UseHealthChecks(app); return(app); }
public ActiveRequestCounterEndpointMiddleware(RequestDelegate next, MetricsOptions options, AspNetMetricsContext metricsContext) : base(options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _next = next; _activeRequests = metricsContext.Context.GetWebApplicationContext() .Counter("Active Requests", Unit.Custom("ActiveRequests")); }
public PostAndPutRequestSizeHistogramMiddleware(RequestDelegate next, MetricsOptions options, AspNetMetricsContext metricsContext) : base(options) { if (next == null) { throw new ArgumentNullException(nameof(next)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _next = next; _histogram = metricsContext.Context.GetWebApplicationContext() .Histogram("Web Request Post & Put Size", Unit.Bytes, SamplingType.Default); }