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); }
/// <summary> /// Metoda specialne pro WPF aplikace, ktere nepotrebuji zadny runner, ale hodi se logovani, metriky a konfigurace /// </summary> /// <returns></returns> public ServiceCollection Build() { var services = new ServiceCollection(); // configuration var config = DefaultConfiguration.Create(configPaths.ToArray(), args); DefaultConfiguration.Configure(services, config); // app context var name = config.GetValue <string>("app:name", null); var env = config.GetValue <string>("app:env", null); var appInfo = new AppInfo(args, name, env); services.AddSingleton(appInfo); // logging var logsOptions = LogsOptions.Create(config, appInfo.Name); var(loggerFactory, defaultLogger) = DefaultLogging.Create(logsOptions, appInfo); DefaultLogging.ConfigureServices(services, loggerFactory, defaultLogger); // metrics var metricsOptions = Conventions.MetricsOptions.Create(config); IMetricsRoot metrics = DefaultMetrics.Create(metricsOptions, appInfo); DefaultMetrics.ConfigureServices(services, metrics, metricsOptions); // log few details about so far configured services for debugging purposes defaultLogger.Debug("StartUp: application {appInfo}", appInfo); defaultLogger.Debug("StartUp: logging {options}", logsOptions); defaultLogger.Debug("StartUp: metrics {options}", metricsOptions); return(services); }
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(); }
/// <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)); }
public MetricsFixture() { var metricsLogger = _loggerFactory.CreateLogger <DefaultAdvancedMetrics>(); var healthFactoryLogger = _loggerFactory.CreateLogger <HealthCheckFactory>(); var clock = new TestClock(); var options = new AppMetricsOptions { DefaultSamplingType = SamplingType.LongTerm }; Func <string, IMetricContextRegistry> newContextRegistry = name => new DefaultMetricContextRegistry(name); var registry = new DefaultMetricsRegistry(_loggerFactory, options, clock, new EnvironmentInfoProvider(), newContextRegistry); var healthCheckFactory = new HealthCheckFactory(healthFactoryLogger); var advancedContext = new DefaultAdvancedMetrics(metricsLogger, options, clock, new DefaultMetricsFilter(), registry, healthCheckFactory); Metrics = new DefaultMetrics(options, registry, advancedContext); }
private (IServiceProvider, AppInfo, ILogger) BuildImpl() { var services = new ServiceCollection(); // configuration var config = DefaultConfiguration.Create(configPaths.ToArray(), args); DefaultConfiguration.Configure(services, config); // app context var name = config.GetValue <string>("app:name", null); var env = config.GetValue <string>("app:env", null); var appInfo = new AppInfo(args, name, env); services.AddSingleton(appInfo); // logging var logsOptions = LogsOptions.Create(config, appInfo.Name); var(loggerFactory, defaultLogger) = DefaultLogging.Create(logsOptions, appInfo); DefaultLogging.ConfigureServices(services, loggerFactory, defaultLogger); // metrics var metricsOptions = Conventions.MetricsOptions.Create(config); IMetricsRoot metrics = DefaultMetrics.Create(metricsOptions, appInfo); DefaultMetrics.ConfigureServices(services, metrics, metricsOptions); // log few details about so far configured services for debugging purposes defaultLogger.Debug("StartUp: application {appInfo}", appInfo); defaultLogger.Debug("StartUp: logging {options}", logsOptions); defaultLogger.Debug("StartUp: metrics {options}", metricsOptions); // execute registered service installers foreach (var installer in installers.Values) { defaultLogger.Debug($"StartUp: service installer {installer.GetType().FullName}"); installer.Install(services, config); } var provider = services.BuildServiceProvider(validateScopes: true); return(provider, appInfo, defaultLogger); }
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); }