Esempio n. 1
0
        /// <summary>
        /// If the user as explictity set a formatter us this as the default formatter to output metrics.
        /// </summary>
        /// <param name="reporter">The reporter to set the user configured formatter</param>
        private void UseUserConfiguredFormatter(IReportMetrics reporter)
        {
            var formatter = _formatters.FirstOrDefault();

            if (formatter != null)
            {
                reporter.Formatter = formatter;
            }
        }
Esempio n. 2
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));
        }