示例#1
0
        public MetricsFixture()
        {
            var healthFactoryLogger = _loggerFactory.CreateLogger <HealthCheckFactory>();
            var clock   = new TestClock();
            var options = new AppMetricsOptions();
            Func <string, IMetricContextRegistry> newContextRegistry = name => new DefaultMetricContextRegistry(name);
            var registry             = new DefaultMetricsRegistry(_loggerFactory, options, clock, new EnvironmentInfoProvider(), newContextRegistry);
            var healthCheckFactory   = new HealthCheckFactory(healthFactoryLogger);
            var metricBuilderFactory = new DefaultMetricsBuilderFactory();
            var filter                        = new DefaultMetricsFilter();
            var dataManager                   = new DefaultMetricValuesProvider(filter, registry);
            var healthStatusProvider          = new DefaultHealthProvider(_loggerFactory.CreateLogger <DefaultHealthProvider>(), healthCheckFactory);
            var metricsManagerFactory         = new DefaultMeasureMetricsProvider(registry, metricBuilderFactory, clock);
            var metricsManagerAdvancedFactory = new DefaultMetricsProvider(registry, metricBuilderFactory, clock);
            var metricsManager                = new DefaultMetricsManager(registry, _loggerFactory.CreateLogger <DefaultMetricsManager>());

            Metrics = new DefaultMetrics(
                clock,
                filter,
                metricsManagerFactory,
                metricBuilderFactory,
                metricsManagerAdvancedFactory,
                dataManager,
                metricsManager,
                healthStatusProvider);
        }
        public HealthCheckRegistryTests()
        {
            _metircsSetup = healthCheckFactory =>
            {
                var clock   = new TestClock();
                var options = new AppMetricsOptions();
                Func <string, IMetricContextRegistry> newContextRegistry = name => new DefaultMetricContextRegistry(name);
                var registry = new DefaultMetricsRegistry(
                    LoggerFactory,
                    options,
                    clock,
                    new EnvironmentInfoProvider(),
                    newContextRegistry);
                var metricBuilderFactory = new DefaultMetricsBuilderFactory();
                var filter        = new DefaultMetricsFilter();
                var healthManager = new DefaultHealthProvider(LoggerFactory.CreateLogger <DefaultHealthProvider>(), healthCheckFactory);
                var dataManager   = new DefaultMetricValuesProvider(
                    filter,
                    registry);

                var metricsManagerFactory         = new DefaultMeasureMetricsProvider(registry, metricBuilderFactory, clock);
                var metricsManagerAdvancedFactory = new DefaultMetricsProvider(registry, metricBuilderFactory, clock);
                var metricsManager = new DefaultMetricsManager(registry, LoggerFactory.CreateLogger <DefaultMetricsManager>());

                return(new DefaultMetrics(
                           clock,
                           filter,
                           metricsManagerFactory,
                           metricBuilderFactory,
                           metricsManagerAdvancedFactory,
                           dataManager,
                           metricsManager,
                           healthManager));
            };
        }
示例#3
0
        public MetricsReportingFixture()
        {
            var healthFactoryLogger = _loggerFactory.CreateLogger <HealthCheckFactory>();
            var options             = new AppMetricsOptions();
            var clock = new TestClock();

            IMetricContextRegistry NewContextRegistry(string name) => new DefaultMetricContextRegistry(name);

            var registry             = new DefaultMetricsRegistry(_loggerFactory, options, clock, new EnvironmentInfoProvider(), NewContextRegistry);
            var healthCheckFactory   = new HealthCheckFactory(healthFactoryLogger);
            var metricBuilderFactory = new DefaultMetricsBuilderFactory();
            var filter        = new DefaultMetricsFilter();
            var healthManager = new DefaultHealthProvider(new Lazy <IMetrics>(() => Metrics), _loggerFactory.CreateLogger <DefaultHealthProvider>(), healthCheckFactory);
            var dataManager   = new DefaultMetricValuesProvider(
                filter,
                registry);

            var metricsManagerFactory         = new DefaultMeasureMetricsProvider(registry, metricBuilderFactory, clock);
            var metricsManagerAdvancedFactory = new DefaultMetricsProvider(registry, metricBuilderFactory, clock);
            var metricsManager = new DefaultMetricsManager(registry, _loggerFactory.CreateLogger <DefaultMetricsManager>());

            Metrics = new DefaultMetrics(
                clock,
                filter,
                metricsManagerFactory,
                metricBuilderFactory,
                metricsManagerAdvancedFactory,
                dataManager,
                metricsManager,
                healthManager);

            RecordSomeMetrics();
        }
示例#4
0
        /// <inheritdoc />
        public IMetricsRoot Build()
        {
            IMetricsRegistry registry = new NullMetricsRegistry();

            if (_options == null)
            {
                _options = new MetricsOptions();
            }

            if (_options.Enabled)
            {
                registry = new DefaultMetricsRegistry(_options.DefaultContextLabel, _clock, ContextRegistry);
            }

            if (_metricsOutputFormatters.Count == 0)
            {
                _metricsOutputFormatters.Add(new MetricsTextOutputFormatter());
            }

            if (_envFormatters.Count == 0)
            {
                _envFormatters.Add(new EnvInfoTextOutputFormatter());
            }

            var builderFactory = new DefaultMetricsBuilderFactory(_defaultSamplingReservoir);
            var measure        = new DefaultMeasureMetricsProvider(registry, builderFactory, _clock);
            var provider       = new DefaultMetricsProvider(registry, builderFactory, _clock);
            var snapshot       = new DefaultMetricValuesProvider(_metricsFilter, registry);
            var manage         = new DefaultMetricsManager(registry);
            var metrics        = new DefaultMetrics(_clock, _metricsFilter, measure, builderFactory, provider, snapshot, manage);
            var defaultMetricsOutputFormatter = _defaultMetricsOutputFormatter ?? _metricsOutputFormatters.FirstOrDefault();
            var defaultEnvOutputFormatter     = _defauEnvOutputFormatter ?? _envFormatters.FirstOrDefault();

            if (CanReport())
            {
                _metricsReportRunner = new DefaultMetricsReportRunner(metrics, _reporters);
            }

            return(new MetricsRoot(
                       metrics,
                       _options,
                       _metricsOutputFormatters,
                       _envFormatters,
                       defaultMetricsOutputFormatter,
                       defaultEnvOutputFormatter,
                       _environmentInfoProvider,
                       _reporters,
                       _metricsReportRunner));

            IMetricContextRegistry ContextRegistry(string context) =>
            new DefaultMetricContextRegistry(context, new GlobalMetricTags(_options.GlobalTags));
        }
示例#5
0
        public MetricsFixture()
        {
            Clock = new TestClock();
            var options = new MetricsOptions();

            IMetricContextRegistry NewContextRegistry(string name) => new DefaultMetricContextRegistry(name);

            var registry             = new DefaultMetricsRegistry(options.DefaultContextLabel, Clock, NewContextRegistry);
            var metricBuilderFactory = new DefaultMetricsBuilderFactory(new DefaultSamplingReservoirProvider(() => new DefaultForwardDecayingReservoir()));
            var filter                        = new MetricsFilter();
            var dataManager                   = new DefaultMetricValuesProvider(filter, registry);
            var metricsManagerFactory         = new DefaultMeasureMetricsProvider(registry, metricBuilderFactory, Clock);
            var metricsManagerAdvancedFactory = new DefaultMetricsProvider(registry, metricBuilderFactory, Clock);
            var metricsManager                = new DefaultMetricsManager(registry);

            Metrics = new DefaultMetrics(
                Clock,
                filter,
                metricsManagerFactory,
                metricBuilderFactory,
                metricsManagerAdvancedFactory,
                dataManager,
                metricsManager);
        }