public void Can_set_global_tags_on_metric_options() { // Arrange var environmentBuilder = new EnvironmentInfoProvider(); var environmentInfo = environmentBuilder.Build(); var expected = new GlobalMetricTags( new Dictionary <string, string> { { "machine_name", environmentInfo.MachineName }, { "app_name", environmentInfo.EntryAssemblyName }, { "app_version", environmentInfo.EntryAssemblyVersion } }); var options = new MetricsOptions(); // Act options.WithGlobalTags( (globalTags, envInfo) => { globalTags.Add("machine_name", envInfo.MachineName); globalTags.Add("app_name", envInfo.EntryAssemblyName); globalTags.Add("app_version", envInfo.EntryAssemblyVersion); }); // Assert options.GlobalTags.Should().Equal(expected); }
public static AppMetricsOptions WithGlobalTags(this AppMetricsOptions options, Action <Dictionary <string, string>, EnvironmentInfo> setupAction) { var environmentBuilder = new EnvironmentInfoProvider(); var environmentInfo = environmentBuilder.Build(); setupAction(options.GlobalTags, environmentInfo); return(options); }
// ReSharper disable UnusedParameter.Local - next required by middleware components public EnvInfoMiddleware( RequestDelegate next, ILogger <EnvInfoMiddleware> logger, IEnvResponseWriter environmentInfoResponseWriter, EnvironmentInfoProvider environmentInfoProvider) // ReSharper restore UnusedParameter.Local { _logger = logger; _environmentInfo = environmentInfoProvider.Build(); _envResponseWriter = environmentInfoResponseWriter ?? throw new ArgumentNullException(nameof(environmentInfoResponseWriter)); }
/// <summary> /// Writes header to the user console (should be called only once at program startup). /// </summary> /// <param name="appName">The application name.</param> private void WriteHeader(string appName) { var environmentInfoProvider = new EnvironmentInfoProvider(); var osInfo = environmentInfoProvider.OSInfo; var cpuPlatform = environmentInfoProvider.CPUPlatformVersion; var processPlatform = environmentInfoProvider.ProcessPlatformVersion; var coresCount = environmentInfoProvider.CPUCoresCount; WriteLine($"$g{appName}$w | {osInfo} " + $"(CPU $c{cpuPlatform}$w, {coresCount}$w | Process $c{processPlatform}$w)"); }
public EnvironmentInfoMiddleware( RequestDelegate next, AspNetMetricsOptions aspNetOptions, ILoggerFactory loggerFactory, IMetrics metrics, IEnvironmentInfoResponseWriter environmentInfoResponseWriter, EnvironmentInfoProvider environmentInfoProvider) : base(next, aspNetOptions, loggerFactory, metrics) { _environmentInfoProvider = environmentInfoProvider; _environmentInfoResponseWriter = environmentInfoResponseWriter ?? throw new ArgumentNullException(nameof(environmentInfoResponseWriter)); _next = next ?? throw new ArgumentNullException(nameof(next)); }
public DefaultMetricsRegistry( ILoggerFactory loggerFactory, AppMetricsOptions options, IClock clock, EnvironmentInfoProvider environmentInfoProvider, Func <string, IMetricContextRegistry> newContextRegistry) { _logger = loggerFactory.CreateLogger <DefaultMetricContextRegistry>(); _environmentInfoProvider = environmentInfoProvider; _clock = clock; _newContextRegistry = newContextRegistry; _defaultContextLabel = options.DefaultContextLabel; _contexts.TryAdd(_defaultContextLabel, newContextRegistry(_defaultContextLabel)); }
public MetricsRoot( IMetrics metrics, MetricsOptions options, MetricsFormatterCollection metricsOutputFormatters, EnvFormatterCollection envOutputFormatters, IMetricsOutputFormatter defaultMetricsOutputFormatter, IEnvOutputFormatter defaultEnvOutputFormatter, EnvironmentInfoProvider environmentInfoProvider, MetricsReporterCollection reporterCollection, IRunMetricsReports reporter) { Options = options ?? throw new ArgumentNullException(nameof(options)); _metrics = metrics ?? throw new ArgumentNullException(nameof(metrics)); ReportRunner = reporter ?? throw new ArgumentNullException(nameof(reporter)); _environmentInfoProvider = new EnvironmentInfoProvider(); Reporters = reporterCollection ?? new MetricsReporterCollection(); OutputMetricsFormatters = metricsOutputFormatters ?? new MetricsFormatterCollection(); OutputEnvFormatters = envOutputFormatters ?? new EnvFormatterCollection(); DefaultOutputMetricsFormatter = defaultMetricsOutputFormatter; DefaultOutputEnvFormatter = defaultEnvOutputFormatter; _environmentInfoProvider = environmentInfoProvider; }
public ConfigureAppMetricsOptions(EnvironmentInfoProvider environmentInfoProvider) { _environmentInfo = environmentInfoProvider.Build(); }