public MetricsDataValueSource GetData(IMetricsFilter filter)
        {
            _logger.RetrievedMetricsData();

            if (_contexts.Count == 0)
            {
                return(MetricsDataValueSource.Empty);
            }

            var environment = _environmentInfoProvider.Build();

            var contexts = _contexts.Values.Select(g => new MetricsContextValueSource(
                                                       g.Context,
                                                       g.DataProvider.Gauges.ToArray(),
                                                       g.DataProvider.Counters.ToArray(),
                                                       g.DataProvider.Meters.ToArray(),
                                                       g.DataProvider.Histograms.ToArray(),
                                                       g.DataProvider.Timers.ToArray(),
                                                       g.DataProvider.ApdexScores.ToArray()
                                                       ));

            var data = new MetricsDataValueSource(_clock.UtcDateTime, environment, contexts);

            _logger.GettingMetricsData();

            return(data.Filter(filter));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 4
0
 // 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));
 }
        // ReSharper disable UnusedMember.Global
        public async Task Invoke(HttpContext context)
        // ReSharper restore UnusedMember.Global
        {
            if (Options.EnvironmentInfoEndpointEnabled && Options.EnvironmentInfoEndpoint.IsPresent() && Options.EnvironmentInfoEndpoint == context.Request.Path)
            {
                Logger.MiddlewareExecuting(GetType());

                context.Response.Headers["Content-Type"] = new[] { _environmentInfoResponseWriter.ContentType };
                context.SetNoCacheHeaders();
                context.Response.StatusCode = (int)HttpStatusCode.OK;

                await _environmentInfoResponseWriter.WriteAsync(context, _environmentInfoProvider.Build(), context.RequestAborted).ConfigureAwait(false);

                Logger.MiddlewareExecuted(GetType());

                return;
            }

            await _next(context);
        }
Esempio n. 6
0
 public ConfigureAppMetricsOptions(EnvironmentInfoProvider environmentInfoProvider)
 {
     _environmentInfo = environmentInfoProvider.Build();
 }