Exemplo n.º 1
0
        private static void AddMetricsObservers(IServiceCollection services, MetricsObserverOptions observerOptions)
        {
            if (observerOptions.AspNetCoreHosting)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <IDiagnosticObserver, AspNetCoreHostingObserver>());
            }

            if (observerOptions.GCEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, GCEventsListener>());
            }

            if (observerOptions.EventCounterEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, EventCounterListener>());
            }

            if (observerOptions.ThreadPoolEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, ThreadPoolEventsListener>());
            }

            if (observerOptions.HystrixEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, HystrixEventsListener>());
            }
        }
Exemplo n.º 2
0
        public static void AddMetricsActuator(this IServiceCollection services, IConfiguration config)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            services.TryAddSingleton <IDiagnosticsManager, DiagnosticsManager>();
            services.TryAddEnumerable(ServiceDescriptor.Singleton <IHostedService, DiagnosticServices>());

            services.AddActuatorManagementOptions(config);

            var options = new MetricsEndpointOptions(config);

            services.TryAddSingleton <IMetricsEndpointOptions>(options);
            services.RegisterEndpointOptions(options);

            var observerOptions = new MetricsObserverOptions(config);

            services.TryAddSingleton <IMetricsObserverOptions>(observerOptions);

            AddMetricsObservers(services, observerOptions);

            services.TryAddEnumerable(ServiceDescriptor.Singleton <MetricExporter, SteeltoeExporter>());
            services.AddOpenTelemetry();

            services.TryAddSingleton((provider) => provider.GetServices <MetricExporter>().OfType <SteeltoeExporter>().SingleOrDefault());
            services.TryAddSingleton <MetricsEndpoint>();
        }
        public static void AddMetricsActuator(this IServiceCollection services, IConfiguration config = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            config ??= services.BuildServiceProvider().GetService <IConfiguration>();
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            services.TryAddSingleton <IDiagnosticsManager, DiagnosticsManager>();
            services.TryAddEnumerable(ServiceDescriptor.Singleton <IHostedService, DiagnosticServices>());

            services.AddActuatorManagementOptions(config);
            services.AddMetricsActuatorServices(config);

            var observerOptions = new MetricsObserverOptions(config);

            services.TryAddSingleton <IMetricsObserverOptions>(observerOptions);

            AddMetricsObservers(services, observerOptions);

#pragma warning disable CS0618 // Type or member is obsolete
            services.TryAddEnumerable(ServiceDescriptor.Singleton <MetricExporter, SteeltoeExporter>());
            services.AddOpenTelemetry();

            services.TryAddSingleton((provider) => provider.GetServices <MetricExporter>().OfType <SteeltoeExporter>().SingleOrDefault());
#pragma warning restore CS0618 // Type or member is obsolete
            services.AddActuatorEndpointMapping <MetricsEndpoint>();
        }
Exemplo n.º 4
0
        public static void AddPrometheusActuator(this IServiceCollection services, IConfiguration config = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            config ??= services.BuildServiceProvider().GetService <IConfiguration>();
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            services.TryAddSingleton <IDiagnosticsManager, DiagnosticsManager>();
            services.TryAddEnumerable(ServiceDescriptor.Singleton <IHostedService, DiagnosticServices>());

            services.TryAddEnumerable(ServiceDescriptor.Singleton <IManagementOptions>(new ActuatorManagementOptions(config)));

            var metricsEndpointOptions = new MetricsEndpointOptions(config);

            services.TryAddSingleton <IMetricsEndpointOptions>(metricsEndpointOptions);

            var observerOptions = new MetricsObserverOptions(config);

            services.TryAddSingleton <IMetricsObserverOptions>(observerOptions);

            services.AddPrometheusActuatorServices(config);

            AddMetricsObservers(services, observerOptions);
            services.TryAddEnumerable(ServiceDescriptor.Singleton <MetricExporter, PrometheusExporter>());
            services.AddOpenTelemetry();
            services.TryAddSingleton((provider) => provider.GetServices <MetricExporter>().OfType <PrometheusExporter>().SingleOrDefault());
            services.AddActuatorEndpointMapping <PrometheusScraperEndpoint>();
        }
        private static void AddMetricsObservers(IServiceCollection services, MetricsObserverOptions observerOptions)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            if (observerOptions.AspNetCoreHosting)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <IDiagnosticObserver, AspNetCoreHostingObserver>());
            }

            if (observerOptions.HttpClientCore)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <IDiagnosticObserver, HttpClientCoreObserver>());
            }

            if (observerOptions.HttpClientDesktop)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <IDiagnosticObserver, HttpClientDesktopObserver>());
            }

            if (observerOptions.GCEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, GCEventsListener>());
            }

            if (observerOptions.EventCounterEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, EventCounterListener>());
            }

            if (observerOptions.ThreadPoolEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, ThreadPoolEventsListener>());
            }

            if (observerOptions.HystrixEvents)
            {
                services.TryAddEnumerable(ServiceDescriptor.Singleton <EventListener, HystrixEventsListener>());
            }
#pragma warning restore CS0618 // Type or member is obsolete
        }