コード例 #1
0
        /// <inheritdoc />
        public IMetricsBuilder Using(IEnvOutputFormatter formatter)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            _formatter(formatter);

            return(Builder);
        }
コード例 #2
0
        public DefaultEnvResponseWriter(
            IEnvOutputFormatter fallbackFormatter,
            IReadOnlyCollection <IEnvOutputFormatter> formatters)
        {
            if (formatters == null)
            {
                throw new ArgumentNullException(nameof(formatters));
            }

            _formatters        = new EnvFormatterCollection(formatters.ToList());
            _fallbackFormatter = fallbackFormatter ?? throw new ArgumentNullException(nameof(fallbackFormatter));
        }
コード例 #3
0
 private static void UseEnvInfoMiddleware(
     IApplicationBuilder app,
     IOptions<MetricsEndpointsHostingOptions> endpointHostingOptionsAccessor,
     IOptions<MetricEndpointsOptions> endpointsOptionsAccessor,
     IEnvOutputFormatter formatter = null)
 {
     if (endpointsOptionsAccessor.Value.EnvironmentInfoEndpointEnabled &&
         endpointHostingOptionsAccessor.Value.EnvironmentInfoEndpoint.IsPresent())
     {
         app.UseWhen(
             context => ShouldUseEnvInfo(endpointHostingOptionsAccessor, endpointsOptionsAccessor, context),
             appBuilder =>
             {
                 var responseWriter = GetEnvInfoResponseWriter(appBuilder.ApplicationServices, formatter);
                 appBuilder.UseMiddleware<EnvInfoMiddleware>(responseWriter);
             });
     }
 }
コード例 #4
0
 public MetricsRoot(
     IMetrics metrics,
     MetricsOptions options,
     MetricsFormatterCollection metricsOutputFormatters,
     EnvFormatterCollection envOutputFormatters,
     IMetricsOutputFormatter defaultMetricsOutputFormatter,
     IEnvOutputFormatter defaultEnvOutputFormatter,
     EnvironmentInfoProvider environmentInfoProvider,
     MetricsReporterCollection reporterCollection,
     IRunMetricsReports reporter)
 {
     Options                       = options ?? throw new ArgumentNullException(nameof(options));
     _metrics                      = metrics ?? throw new ArgumentNullException(nameof(metrics));
     ReportRunner                  = reporter ?? throw new ArgumentNullException(nameof(reporter));
     _environmentInfoProvider      = new EnvironmentInfoProvider();
     Reporters                     = reporterCollection ?? new MetricsReporterCollection();
     OutputMetricsFormatters       = metricsOutputFormatters ?? new MetricsFormatterCollection();
     OutputEnvFormatters           = envOutputFormatters ?? new EnvFormatterCollection();
     DefaultOutputMetricsFormatter = defaultMetricsOutputFormatter;
     DefaultOutputEnvFormatter     = defaultEnvOutputFormatter;
     _environmentInfoProvider      = environmentInfoProvider;
 }
コード例 #5
0
 public DefaultEnvResponseWriter(IEnvOutputFormatter formatter)
 {
     _formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
 }
コード例 #6
0
        private static IEnvResponseWriter GetEnvInfoResponseWriter(IServiceProvider serviceProvider, IEnvOutputFormatter formatter = null)
        {
            var formatters = serviceProvider.GetRequiredService<IReadOnlyCollection<IEnvOutputFormatter>>();

            if (formatter != null)
            {
                var responseWriter = new DefaultEnvResponseWriter(formatter, formatters);
                return responseWriter;
            }

            var options = serviceProvider.GetRequiredService<IOptions<MetricEndpointsOptions>>();
            return new DefaultEnvResponseWriter(options.Value.EnvInfoEndpointOutputFormatter, formatters);
        }
コード例 #7
0
        /// <summary>
        ///     Adds App Metrics Environment Information middleware to the <see cref="IApplicationBuilder" /> request execution
        ///     pipeline.
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder" />.</param>
        /// <param name="formatter">
        ///     Overrides all configured <see cref="IEnvOutputFormatter" />, matching on accept headers
        ///     won't apply.
        /// </param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IApplicationBuilder UseEnvInfoEndpoint(this IApplicationBuilder app, IEnvOutputFormatter formatter)
        {
            EnsureMetricsAdded(app);

            var endpointHostingOptionsAccessor = app.ApplicationServices.GetRequiredService<IOptions<MetricsEndpointsHostingOptions>>();
            var endpointsOptionsAccessor = app.ApplicationServices.GetRequiredService<IOptions<MetricEndpointsOptions>>();

            UseEnvInfoMiddleware(app, endpointHostingOptionsAccessor, endpointsOptionsAccessor, formatter);

            return app;
        }