Exemple #1
0
        protected void SetupServices(
            IServiceCollection services,
            AppMetricsOptions appMetricsOptions,
            AspNetMetricsOptions aspNetMetricsOptions,
            IFilterMetrics filter = null,
            IEnumerable <HealthCheckResult> healthChecks = null)
        {
            services
            .AddLogging()
            .AddRouting(options => { options.LowercaseUrls = true; });

            services.AddMvc(options => options.AddMetricsResourceFilter());

            var builder = services
                          .AddMetrics(
                options =>
            {
                options.DefaultContextLabel = appMetricsOptions.DefaultContextLabel;
                options.MetricsEnabled      = appMetricsOptions.MetricsEnabled;
            })
                          .AddJsonSerialization()
                          .AddDefaultReservoir(() => new DefaultAlgorithmRReservoir(1028))
                          .AddClockType <TestClock>()
                          .AddHealthChecks(
                factory =>
            {
                var checks = healthChecks != null
                            ? healthChecks.ToList()
                            : new List <HealthCheckResult>();

                for (var i = 0; i < checks.Count; i++)
                {
                    var check = checks[i];
                    factory.Register("Check" + i, () => Task.FromResult(check));
                }
            })
                          .AddMetricsMiddleware(
                options =>
            {
                options.MetricsTextEndpointEnabled = aspNetMetricsOptions.MetricsTextEndpointEnabled;
                options.HealthEndpointEnabled      = aspNetMetricsOptions.HealthEndpointEnabled;
                options.MetricsEndpointEnabled     = aspNetMetricsOptions.MetricsEndpointEnabled;
                options.PingEndpointEnabled        = aspNetMetricsOptions.PingEndpointEnabled;
                options.OAuth2TrackingEnabled      = aspNetMetricsOptions.OAuth2TrackingEnabled;

                options.HealthEndpoint      = aspNetMetricsOptions.HealthEndpoint;
                options.MetricsEndpoint     = aspNetMetricsOptions.MetricsEndpoint;
                options.MetricsTextEndpoint = aspNetMetricsOptions.MetricsTextEndpoint;
                options.PingEndpoint        = aspNetMetricsOptions.PingEndpoint;

                options.IgnoredRoutesRegexPatterns = aspNetMetricsOptions.IgnoredRoutesRegexPatterns;
                options.IgnoredHttpStatusCodes     = aspNetMetricsOptions.IgnoredHttpStatusCodes;
            });

            if (filter != null)
            {
                builder.AddGlobalFilter(filter);
            }
        }
        public void Throws_if_missing_request_duration_histogram_labels()
        {
            var options = new AspNetMetricsOptions
            {
                ConfigureRequestDurationHistogram = config => config.LabelNames = new[] { "foo" }
            };

            Assert.Throws <ArgumentException>(() => new AspNetMetricsObserver(options, _metrics));
        }
        public void Throws_if_missing_default_requests_in_progress_labels()
        {
            var options = new AspNetMetricsOptions
            {
                ConfigureRequestsInProgressGauge = config => config.LabelNames = new[] { "foo" }
            };

            Assert.Throws <ArgumentException>(() => new AspNetMetricsObserver(options, _metrics));
        }
        public void Throws_if_missing_default_error_total_counter_labels()
        {
            var options = new AspNetMetricsOptions
            {
                ConfigureErrorTotalCounter = config => config.LabelNames = new[] { "foo" }
            };

            Assert.Throws <ArgumentException>(() => new AspNetMetricsObserver(options, _metrics));
        }
        public void Throws_if_missing_request_duration_summary_labels()
        {
            var options = new AspNetMetricsOptions
            {
                ConfigureRequestDurationSummary = config => config.LabelNames = new[] { "foo" },
                RequestDurationMetricType       = ObserverMetricType.Summary
            };

            Assert.Throws <ArgumentException>(() => new AspNetMetricsObserver(options, _metrics));
        }
        public void Can_configure_error_total_counter()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureErrorTotalCounter = config => invoked = true
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions();

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsEndpoint = new PathString("/metrics-json")
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions();

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = false
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
        public void Can_configure_request_duration_histogram()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureRequestDurationHistogram = config => invoked = true
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
        public void Can_configure_requests_in_progress_gauge()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureRequestsInProgressGauge = config => invoked = true
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
        public void Can_configure_request_duration_summary()
        {
            bool invoked = false;
            var  options = new AspNetMetricsOptions
            {
                ConfigureRequestDurationSummary = config => invoked = true,
                RequestDurationMetricType       = ObserverMetricType.Summary
            };

            _ = new AspNetMetricsObserver(options, _metrics);
            invoked.ShouldBeTrue();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultSamplingType = SamplingType.LongTerm,
                MetricsEnabled      = true,
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions();

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions,
                          new DefaultMetricsFilter().WhereType(MetricType.Counter));
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultSamplingType = SamplingType.LongTerm
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsEndpoint = new PathString("/metrics-json")
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
Exemple #14
0
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultSamplingType = SamplingType.LongTerm
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = false
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
        public void can_override_settings_from_configuration()
        {
            var options  = new AspNetMetricsOptions();
            var provider = SetupServicesAndConfiguration(
                (o) =>
            {
                o.ApdexTSeconds         = 0.7;
                o.ApdexTrackingEnabled  = true;
                o.HealthEndpointEnabled = true;
            });

            Action resolveOptions = () => { options = provider.GetRequiredService <AspNetMetricsOptions>(); };

            resolveOptions.ShouldNotThrow();
            options.ApdexTrackingEnabled.Should().Be(true);
            options.ApdexTSeconds.Should().Be(0.7);
            options.HealthEndpointEnabled.Should().Be(true);
        }
        public void can_load_settings_from_configuration()
        {
            var    options        = new AspNetMetricsOptions();
            var    provider       = SetupServicesAndConfiguration();
            Action resolveOptions = () => { options = provider.GetRequiredService <AspNetMetricsOptions>(); };

            resolveOptions.ShouldNotThrow();
            options.ApdexTrackingEnabled.Should().Be(false);
            options.ApdexTSeconds.Should().Be(0.8);
            options.HealthEndpoint.Should().Be("/health-test");
            options.MetricsEndpoint.Should().Be("/metrics-test");
            options.MetricsTextEndpoint.Should().Be("/metrics-text-test");
            options.PingEndpoint.Should().Be("/ping-test");
            options.HealthEndpointEnabled.Should().Be(false);
            options.MetricsTextEndpointEnabled.Should().Be(false);
            options.MetricsEndpointEnabled.Should().Be(false);
            options.PingEndpointEnabled.Should().Be(false);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultContextLabel = "testing",
                MetricsEnabled      = true
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = true,
                HealthEndpointEnabled      = true,
                MetricsEndpointEnabled     = true,
                PingEndpointEnabled        = true
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
Exemple #18
0
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                MetricsEnabled = true
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = true,
                HealthEndpointEnabled      = true,
                MetricsEndpointEnabled     = true,
                PingEndpointEnabled        = true,
                OAuth2TrackingEnabled      = true
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
Exemple #19
0
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultContextLabel = "testing",
                MetricsEnabled      = true
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = true,
                HealthEndpointEnabled      = true,
                MetricsEndpointEnabled     = true,
                PingEndpointEnabled        = true
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions,
                          healthChecks: new[] { HealthCheckResult.Healthy(), HealthCheckResult.Degraded(), HealthCheckResult.Unhealthy() });
        }
Exemple #20
0
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultContextLabel = "testing",
                MetricsEnabled      = true
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = true,
                HealthEndpointEnabled      = true,
                MetricsEndpointEnabled     = true,
                PingEndpointEnabled        = true
            };

            aspNetMetricsOptions.IgnoredRoutesRegexPatterns.Add("(?i)^api/test/ignore");

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            var appMetricsOptions = new AppMetricsOptions
            {
                DefaultContextLabel = "testing",
                MetricsEnabled      = true,
                DefaultSamplingType = SamplingType.LongTerm
            };

            var aspNetMetricsOptions = new AspNetMetricsOptions
            {
                MetricsTextEndpointEnabled = true,
                HealthEndpointEnabled      = true,
                MetricsEndpointEnabled     = true,
                PingEndpointEnabled        = true,
                HealthEndpoint             = new PathString("/health-status")
            };

            SetupServices(services, appMetricsOptions, aspNetMetricsOptions);
        }
 public ApdexHealthCheck(Lazy <IMetrics> metrics, AspNetMetricsOptions options)
     : base("Apdex Score")
 {
     _metrics = metrics;
     _options = options;
 }