/// <summary> /// Add performance metrics sender that publishes to DataDog /// </summary> /// <param name="services"></param> /// <param name="datadogConfig"></param> /// <param name="options"></param> /// <param name="tags">Custom tags that will always be publised to DataDog</param> /// <returns><see cref="IServiceCollection"/></returns> public static IServiceCollection AddPerformanceMetricSender( this IServiceCollection services, StatsdConfig datadogConfig = null, PerfMetricsSenderOptions options = null, params MetricTag[] tags) { if (datadogConfig == null) { datadogConfig = new StatsdConfig { StatsdServerName = "localhost", StatsdPort = 8125 } } ; services.AddSingleton <IMetricsPublisher>(svc => new DataDogMetricsPublisher(datadogConfig)); AddMetricsAndHostedService( services, options, tags); return(services); }
private static void AddMetricsAndHostedService( IServiceCollection services, PerfMetricsSenderOptions options = null, params MetricTag[] tags) { services.AddSingleton(options ?? new PerfMetricsSenderOptions { MetricCollectionIntervalInMilliseconds = 60_000 }); services.AddTransient( svc => AvailablePerformanceMetrics.All( tags)); services.AddSingleton <PerfMetricPublisherService>(); services.AddHostedService <PerfMetricSenderService>(); }