public void ConfigureServices(IServiceCollection services) { var appMetricsOptions = new MetricsOptions(); var endpointsOptions = new MetricEndpointsOptions { MetricsTextEndpointEnabled = false, MetricsEndpointEnabled = true }; var trackingOptions = new MetricsWebTrackingOptions(); SetupServices(services, appMetricsOptions, trackingOptions, endpointsOptions); }
protected void SetupServices( IServiceCollection services, MetricsOptions appMetricsOptions, MetricsWebTrackingOptions webTrackingOptions, MetricEndpointsOptions endpointsOptions, IFilterMetrics filter = null) { services.AddLogging().AddRouting(options => { options.LowercaseUrls = true; }); services.AddMvc(options => options.AddMetricsResourceFilter()); var builder = new MetricsBuilder().Configuration.Configure( options => { options.DefaultContextLabel = appMetricsOptions.DefaultContextLabel; options.Enabled = appMetricsOptions.Enabled; }) .OutputEnvInfo.AsPlainText() .OutputEnvInfo.AsJson() .OutputMetrics.AsJson() .OutputMetrics.AsPlainText() .SampleWith.AlgorithmR(1028) .TimeWith.Clock <TestClock>(); if (filter != null) { builder.Filter.With(filter); } services.AddMetrics(builder); services.AddMetricsEndpoints( options => { options.MetricsTextEndpointEnabled = endpointsOptions.MetricsTextEndpointEnabled; options.MetricsEndpointEnabled = endpointsOptions.MetricsEndpointEnabled; }); services.AddMetricsTrackingMiddleware( options => { options.OAuth2TrackingEnabled = webTrackingOptions.OAuth2TrackingEnabled; options.IgnoredRoutesRegexPatterns = webTrackingOptions.IgnoredRoutesRegexPatterns; options.IgnoredHttpStatusCodes = webTrackingOptions.IgnoredHttpStatusCodes; }); }
public void Can_load_settings_from_configuration() { var trackingOptions = new MetricsWebTrackingOptions(); var endpointOptions = new MetricEndpointsOptions(); var provider = SetupServicesAndConfiguration(); Action resolveOptions = () => { trackingOptions = provider.GetRequiredService <IOptions <MetricsWebTrackingOptions> >().Value; }; Action resolveEndpointsOptions = () => { endpointOptions = provider.GetRequiredService <IOptions <MetricEndpointsOptions> >().Value; }; resolveOptions.ShouldNotThrow(); resolveEndpointsOptions.ShouldNotThrow(); trackingOptions.ApdexTrackingEnabled.Should().Be(false); trackingOptions.ApdexTSeconds.Should().Be(0.8); endpointOptions.MetricsTextEndpointEnabled.Should().Be(false); endpointOptions.MetricsEndpointEnabled.Should().Be(false); }
// ReSharper disable UnusedMember.Global public void ConfigureServices(IServiceCollection services) // ReSharper restore UnusedMember.Global { var appMetricsOptions = new MetricsOptions { Enabled = true }; var endpointOptions = new MetricEndpointsOptions(); var trackingOptions = new MetricsWebTrackingOptions(); SetupServices( services, appMetricsOptions, trackingOptions, endpointOptions, new MetricsFilter().WhereType(MetricType.Counter)); }
/// <summary> /// Adds App Metrics services, configuration and middleware to the /// <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />. /// </summary> /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param> /// <param name="setupDelegate">A callback to configure <see cref="MetricEndpointsOptions" />.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <exception cref="ArgumentNullException"> /// <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> cannot be null /// </exception> public static IWebHostBuilder UseMetricsEndpoints( this IWebHostBuilder hostBuilder, Action <WebHostBuilderContext, MetricEndpointsOptions> setupDelegate) { hostBuilder.ConfigureMetrics(); hostBuilder.ConfigureServices( (context, services) => { var endpointOptions = new MetricEndpointsOptions(); services.AddMetricsEndpoints( options => setupDelegate(context, endpointOptions), context.Configuration); services.AddSingleton <IStartupFilter>(new DefaultMetricsEndpointsStartupFilter()); }); return(hostBuilder); }
// ReSharper disable UnusedMember.Global public void ConfigureServices(IServiceCollection services) // ReSharper restore UnusedMember.Global { var appMetricsOptions = new MetricsOptions { DefaultContextLabel = "testing", Enabled = true }; var endpointsOptions = new MetricEndpointsOptions { MetricsTextEndpointEnabled = true, MetricsEndpointEnabled = true }; var trackingOptions = new MetricsWebTrackingOptions(); SetupServices(services, appMetricsOptions, trackingOptions, endpointsOptions); }
public void ConfigureServices(IServiceCollection services) { var appMetricsOptions = new MetricsOptions { Enabled = true }; var endpointsOptions = new MetricEndpointsOptions { MetricsTextEndpointEnabled = true, MetricsEndpointEnabled = true }; var trackingoptions = new MetricsWebTrackingOptions { OAuth2TrackingEnabled = true }; trackingoptions.IgnoredRoutesRegexPatterns.Add("(?i)^api/test/ignore"); SetupServices(services, appMetricsOptions, trackingoptions, endpointsOptions); }