public MetricsDataValueSource GetData(IFilterMetrics filter) { _logger.RetrievedMetricsData(); if (_nullMetricsRegistry.IsValueCreated) { _nullMetricsRegistry.Value.GetData(filter); } 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)); }
public MetricsDataValueSource GetData(IFilterMetrics filter) { Logger.Trace("Getting metrics snaphot"); if (_nullMetricsRegistry.IsValueCreated) { Logger.Trace("Using null metrics registry"); _nullMetricsRegistry.Value.GetData(filter); } if (_contexts.Count == 0) { Logger.Trace("No metrics recorded"); return(MetricsDataValueSource.Empty); } Logger.Trace("Metrics snapshot retrieved containing {ContextCount} contexts", _contexts.Count); 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, contexts); return(data.Filter(filter)); }
public static IReportFactory AddTextFile(this IReportFactory factory, IFilterMetrics filter = null) { var settings = new TextFileReporterSettings(); factory.AddTextFile(settings, filter); return(factory); }
public MetricsDataValueSource Filter(IFilterMetrics filter) { var contexts = Contexts.FilterBy(filter).WhereNotEmpty(); var environment = filter.ReportEnvironment ? Environment : EnvironmentInfo.Empty; return(new MetricsDataValueSource(Timestamp, environment, contexts)); }
protected void SetupServices( IServiceCollection services, AppMetricsOptions appMetricsOptions, AspNetMetricsOptions aspNetMetricsOptions, IFilterMetrics filter = null, IEnumerable <HealthCheckResult> healthChecks = null) { services .AddLogging() .AddRouting(options => { options.LowercaseUrls = true; }); services.AddMvc(options => options.AddMetricsResourceFilter()); var builder = services .AddMetrics( options => { options.DefaultContextLabel = appMetricsOptions.DefaultContextLabel; options.MetricsEnabled = appMetricsOptions.MetricsEnabled; }) .AddJsonSerialization() .AddDefaultReservoir(() => new DefaultAlgorithmRReservoir(1028)) .AddClockType <TestClock>() .AddHealthChecks( factory => { var checks = healthChecks != null ? healthChecks.ToList() : new List <HealthCheckResult>(); for (var i = 0; i < checks.Count; i++) { var check = checks[i]; factory.Register("Check" + i, () => Task.FromResult(check)); } }) .AddMetricsMiddleware( options => { options.MetricsTextEndpointEnabled = aspNetMetricsOptions.MetricsTextEndpointEnabled; options.HealthEndpointEnabled = aspNetMetricsOptions.HealthEndpointEnabled; options.MetricsEndpointEnabled = aspNetMetricsOptions.MetricsEndpointEnabled; options.PingEndpointEnabled = aspNetMetricsOptions.PingEndpointEnabled; options.OAuth2TrackingEnabled = aspNetMetricsOptions.OAuth2TrackingEnabled; options.HealthEndpoint = aspNetMetricsOptions.HealthEndpoint; options.MetricsEndpoint = aspNetMetricsOptions.MetricsEndpoint; options.MetricsTextEndpoint = aspNetMetricsOptions.MetricsTextEndpoint; options.PingEndpoint = aspNetMetricsOptions.PingEndpoint; options.IgnoredRoutesRegexPatterns = aspNetMetricsOptions.IgnoredRoutesRegexPatterns; options.IgnoredHttpStatusCodes = aspNetMetricsOptions.IgnoredHttpStatusCodes; }); if (filter != null) { builder.AddGlobalFilter(filter); } }
public static IReportFactory AddElasticSearch( this IReportFactory factory, ElasticSearchReporterSettings settings, IFilterMetrics filter = null) { factory.AddProvider(new ElasticSearchReporterProvider(settings, filter)); return(factory); }
public static IReportFactory AddGraphite( this IReportFactory factory, GraphiteReporterSettings settings, IFilterMetrics filter = null) { factory.AddProvider(new GraphiteReporterProvider(settings, filter)); return(factory); }
public static IReportFactory AddInfluxDb( this IReportFactory factory, InfluxDBReporterSettings settings, IFilterMetrics filter = null) { factory.AddProvider(new InfluxDbReporterProvider(settings, filter)); return(factory); }
internal MetricsFilterBuilder( IMetricsBuilder metricsBuilder, Action <IFilterMetrics> metricsFilter) { Builder = metricsBuilder ?? throw new ArgumentNullException(nameof(metricsBuilder)); _metricsFilter = metricsFilter ?? throw new ArgumentNullException(nameof(metricsFilter)); _filter = new MetricsFilter(); }
public InfluxDbReporterProvider(InfluxDBReporterSettings settings, IFilterMetrics fitler) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } _settings = settings; Filter = fitler ?? new NoOpMetricsFilter(); }
public TextFileReporterProvider(TextFileReporterSettings settings, IFilterMetrics fitler) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } _settings = settings; Filter = fitler; }
/// <inheritdoc /> public IMetricsBuilder Using <TReportMetrics>(IFilterMetrics filter) where TReportMetrics : IReportMetrics, new() { var reporter = new TReportMetrics { Filter = filter ?? new NullMetricsFilter() }; UseUserConfiguredFormatter(reporter); return(Using(reporter)); }
/// <inheritdoc /> public IMetricsBuilder Using <TReportMetrics>(IFilterMetrics filter, TimeSpan flushInterval) where TReportMetrics : IReportMetrics, new() { var reporter = new TReportMetrics { Filter = filter, FlushInterval = flushInterval }; UseUserConfiguredFormatter(reporter); return(Using(reporter)); }
/// <inheritdoc /> public IMetricsBuilder With(IFilterMetrics filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } _metricsFilter(filter); return(Builder); }
public static IReportFactory AddGraphite( this IReportFactory factory, Uri baseAddress, IFilterMetrics filter = null) { var settings = new GraphiteReporterSettings { GraphiteSettings = new GraphiteSettings(baseAddress) }; factory.AddGraphite(settings, filter); return(factory); }
public static IReportFactory AddElasticSearch( this IReportFactory factory, Uri address, string indexName, IFilterMetrics filter = null) { var settings = new ElasticSearchReporterSettings { ElasticSearchSettings = new ElasticSearchSettings(address, indexName) }; factory.AddElasticSearch(settings, filter); return(factory); }
public static IReportFactory AddInfluxDb( this IReportFactory factory, string database, Uri baseAddress, IFilterMetrics filter = null) { var settings = new InfluxDBReporterSettings { InfluxDbSettings = new InfluxDBSettings(database, baseAddress) }; factory.AddInfluxDb(settings, filter); return(factory); }
public MetricsContextValueSource Filter(IFilterMetrics filter) { if (!filter.IsContextMatch(Context)) { return(Empty); } return(new MetricsContextValueSource( Context, Gauges.Where(filter.IsGaugeMatch), Counters.Where(filter.IsCounterMatch), Meters.Where(filter.IsMeterMatch), Histograms.Where(filter.IsHistogramMatch), Timers.Where(filter.IsTimerMatch), ApdexScores.Where(filter.IsApdexMatch))); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultMetrics" /> class. /// </summary> /// <param name="clock">The clock.</param> /// <param name="filter">The metrics filter.</param> /// <param name="measureMetricsProvider">The factory used to provide access to metric managers.</param> /// <param name="metricsBuilder">The factory used to provide access to metric builders.</param> /// <param name="metricsProvider">The metrics advanced manager factory.</param> /// <param name="dataManager">The data manager.</param> /// <param name="metricsManager">The metrics manager.</param> public DefaultMetrics( IClock clock, IFilterMetrics filter, IMeasureMetrics measureMetricsProvider, IBuildMetrics metricsBuilder, IProvideMetrics metricsProvider, IProvideMetricValues dataManager, IManageMetrics metricsManager) { Clock = clock ?? new StopwatchClock(); Filter = filter ?? new NullMetricsFilter(); Measure = measureMetricsProvider; Build = metricsBuilder; Snapshot = dataManager; Provider = metricsProvider; Manage = metricsManager; }
protected void SetupServices( IServiceCollection services, MetricsOptions appMetricsOptions, MetricsWebTrackingOptions webTrackingOptions, MetricEndpointsOptions endpointsOptions, IFilterMetrics filter = null) { services.AddLogging().AddRouting(options => { options.LowercaseUrls = true; }); services.AddMvc(options => options.AddMetricsResourceFilter()); var builder = new MetricsBuilder().Configuration.Configure( options => { options.DefaultContextLabel = appMetricsOptions.DefaultContextLabel; options.Enabled = appMetricsOptions.Enabled; }) .OutputEnvInfo.AsPlainText() .OutputEnvInfo.AsJson() .OutputMetrics.AsJson() .OutputMetrics.AsPlainText() .SampleWith.AlgorithmR(1028) .TimeWith.Clock <TestClock>(); if (filter != null) { builder.Filter.With(filter); } services.AddMetrics(builder); services.AddMetricsEndpoints( options => { options.MetricsTextEndpointEnabled = endpointsOptions.MetricsTextEndpointEnabled; options.MetricsEndpointEnabled = endpointsOptions.MetricsEndpointEnabled; }); services.AddMetricsTrackingMiddleware( options => { options.OAuth2TrackingEnabled = webTrackingOptions.OAuth2TrackingEnabled; options.IgnoredRoutesRegexPatterns = webTrackingOptions.IgnoredRoutesRegexPatterns; options.IgnoredHttpStatusCodes = webTrackingOptions.IgnoredHttpStatusCodes; }); }
/// <inheritdoc /> public MetricsDataValueSource Get(IFilterMetrics overrideGlobalFilter) { IFilterMetrics filter; if (overrideGlobalFilter == null || overrideGlobalFilter is NullMetricsFilter) { filter = _globalFilter; Logger.Trace("Getting metrics snaphot with custom filter"); } else { filter = overrideGlobalFilter; Logger.Trace("Getting metrics snaphot with global filter"); } return(_registry.GetData(filter)); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultMetrics" /> class. /// </summary> /// <param name="clock">The clock.</param> /// <param name="globalFilter">The global filter.</param> /// <param name="measureMetricsProvider">The factory used to provide access to metric managers.</param> /// <param name="metricsBuilder">The factory used to provide access to metric builders.</param> /// <param name="metricsProvider">The metrics advanced manager factory.</param> /// <param name="dataManager">The data manager.</param> /// <param name="metricsManager">The metrics manager.</param> /// <param name="healthProvider">The health status provider.</param> public DefaultMetrics( IClock clock, IFilterMetrics globalFilter, IMeasureMetrics measureMetricsProvider, IBuildMetrics metricsBuilder, IProvideMetrics metricsProvider, IProvideMetricValues dataManager, IManageMetrics metricsManager, IProvideHealth healthProvider) { Clock = clock ?? new StopwatchClock(); GlobalFilter = globalFilter ?? new NoOpMetricsFilter(); Measure = measureMetricsProvider; Build = metricsBuilder; Snapshot = dataManager; Provider = metricsProvider; Manage = metricsManager; Health = healthProvider; }
public static IReportFactory AddGraphite( this IReportFactory factory, string host, int port, ConnectionType connectionType = ConnectionType.Tcp, string metricTemplate = null, IFilterMetrics filter = null) { var settings = new GraphiteReporterSettings { Host = host, Port = port, ConnectionType = connectionType, MetricNameFormatter = string.IsNullOrEmpty(metricTemplate) ? new GraphiteMetricNameFormatter() : new GraphiteMetricNameFormatter(metricTemplate) }; factory.AddGraphite(settings, filter); return(factory); }
public async Task <bool> GenerateAsync( IMetricReporter reporter, IMetrics metrics, IFilterMetrics reporterMetricsFilter, CancellationToken token) { var startTimestamp = _logger.IsEnabled(LogLevel.Trace) ? Stopwatch.GetTimestamp() : 0; _logger.ReportedStarted(reporter); if (reporterMetricsFilter == default(IFilterMetrics)) { reporterMetricsFilter = metrics.GlobalFilter; } reporter.StartReportRun(metrics); var data = metrics.Snapshot.Get(reporterMetricsFilter); if (data.Environment.Entries.Any() && reporterMetricsFilter.ReportEnvironment) { reporter.ReportEnvironment(data.Environment); } if (reporterMetricsFilter.ReportHealthChecks) { await ReportHealth(reporter, metrics, token); } ReportMetricTypes(reporter, token, data); var result = await reporter.EndAndFlushReportRunAsync(metrics); _logger.ReportRan(reporter, startTimestamp); return(result); }
public static IMetricsHostBuilder AddGlobalFilter(this IMetricsHostBuilder builder, IFilterMetrics filter) { builder.Services.Replace(ServiceDescriptor.Singleton(filter)); return(builder); }
public MetricsDataValueSource GetData(IFilterMetrics filter) { return(MetricsDataValueSource.Empty); }
public static IEnumerable <MetricsContextValueSource> FilterBy(this IEnumerable <MetricsContextValueSource> valueSources, IFilterMetrics filter) { return(valueSources.Select(g => g.Filter(filter))); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultMetricValuesProvider" /> class. /// </summary> /// <param name="globalFilter">The global filter.</param> /// <param name="registry">The registry.</param> public DefaultMetricValuesProvider(IFilterMetrics globalFilter, IMetricsRegistry registry) { _globalFilter = globalFilter ?? new NullMetricsFilter(); _registry = registry ?? new NullMetricsRegistry(); }
/// <inheritdoc /> public IMetricsBuilder Using <TReportMetrics>(IMetricsOutputFormatter formatter, IFilterMetrics filter, TimeSpan flushInterval) where TReportMetrics : IReportMetrics, new() { var reporter = new TReportMetrics { Formatter = formatter, Filter = filter, FlushInterval = flushInterval }; return(Using(reporter)); }
public ElasticSearchReporterProvider(ElasticSearchReporterSettings settings, IFilterMetrics fitler) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); Filter = fitler ?? new NoOpMetricsFilter(); }