Exemplo n.º 1
0
 /// <summary>
 /// Configure Owin metrics endpoint.
 /// </summary>
 /// <param name="config">Action used to configure the Owin Metrics endpoint.</param>
 /// <returns>Chainable configuration object.</returns>
 public OwinMetricsConfig WithMetricsEndpoint(Action<OwinMetricsEndpointConfig> config)
 {
     OwinMetricsEndpointConfig endpointConfig = new OwinMetricsEndpointConfig();
     config(endpointConfig);
     var metricsEndpointMiddleware = new MetricsEndpointMiddleware(endpointConfig, this.context.DataProvider, this.healthStatus);
     this.middlewareRegistration(metricsEndpointMiddleware);
     return this;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Configure Owin metrics endpoint.
        /// </summary>
        /// <param name="config">Action used to configure the Owin Metrics endpoint.</param>
        /// <returns>Chainable configuration object.</returns>
        public OwinMetricsConfig WithMetricsEndpoint(Action <OwinMetricsEndpointConfig> config)
        {
            OwinMetricsEndpointConfig endpointConfig = new OwinMetricsEndpointConfig();

            config(endpointConfig);
            var metricsEndpointMiddleware = new MetricsEndpointMiddleware(endpointConfig, this.context.DataProvider.CurrentMetricsData, this.healthStatus);

            this.middlewareRegistration(metricsEndpointMiddleware);
            return(this);
        }
        public static IAppBuilder UseMetrics(this IAppBuilder app, Action<MetricsConfig> metricsConfigCallback,
            Action<OwinMetricsConfig> owinMetricsConfigCallback,
            Action<OwinMetricsEndpointConfig> owinMetricsEndpointConfigCallback = null)
        {
            var config = Metric.Config;

            metricsConfigCallback(config);

            var endpointConfig = new OwinMetricsEndpointConfig();

            if (owinMetricsEndpointConfigCallback != null)
                owinMetricsEndpointConfigCallback(endpointConfig);

            app.Use((context, next) =>
            {
                if (context.Request.Path.Value.EndsWith("/" + endpointConfig.MetricsEndpointName) && endpointConfig.MetricsEndpointEnabled)
                {
                    return GetFlotWebApp(context.Response);
                }

                if (context.Request.Path.Value.EndsWith("/" + endpointConfig.MetricsJsonEndpointName) && endpointConfig.MetricsJsonEndpointEnabled)
                {
                    return GetJsonContent(context.Response, config);
                }

                if (context.Request.Path.Value.EndsWith("/" + endpointConfig.MetricsHealthEndpointName) && endpointConfig.MetricsHealthEndpointEnabled)
                {
                    return GetHealthStatus(context.Response, config);
                }

                if (context.Request.Path.Value.EndsWith("/" + endpointConfig.MetricsTextEndpointName) && endpointConfig.MetricsTextEndpointEnabled)
                {
                    return GetAsHumanReadable(context.Response, config);
                }

                if (context.Request.Path.Value.EndsWith("/" + endpointConfig.MetricsPingEndpointName) && endpointConfig.MetricsPingEndpointEnabled)
                {
                    return GetPingContent(context.Response);
                }

                return next();
            });

            owinMetricsConfigCallback(new OwinMetricsConfig(app, config.Registry));

            return app;
        }