コード例 #1
0
        private DiagnosticInfo BuildDiagnosticInfo(BuildContext context, IHealthTracker healthTracker)
        {
            var infoSettings = infoSettingsCustomization.Customize(new DiagnosticInfoSettings());
            var info         = new DiagnosticInfo();

            if (infoSettings.AddEnvironmentInfo)
            {
                info.RegisterProvider(CreateEntry("environment-info"), new EnvironmentInfoProvider(context.Datacenters));
            }

            if (infoSettings.AddSystemMetricsInfo)
            {
                info.RegisterProvider(CreateEntry("system-metrics"), new SystemMetricsProvider());
            }

            if (infoSettings.AddLoadedAssembliesInfo)
            {
                info.RegisterProvider(CreateEntry("loaded-assemblies"), new LoadedAssembliesProvider());
            }

            if (infoSettings.AddHealthChecksInfo)
            {
                info.RegisterProvider(CreateEntry("health-checks"), new HealthChecksInfoProvider(healthTracker));
            }

            if (infoSettings.AddConfigurationInfo)
            {
                info.RegisterProvider(CreateEntry("configuration"), new ConfigurationInfoProvider(context.ConfigurationSource));
            }

            if (infoSettings.AddHerculesSinkInfo && context.HerculesSink is HerculesSink realSink)
            {
                info.RegisterProvider(CreateEntry("hercules-sink"), new HerculesSinkInfoProvider(realSink));
            }

            if (infoSettings.AddApplicationMetricsInfo && context.MetricsInfoProvider != null)
            {
                info.RegisterProvider(CreateEntry("application-metrics"), context.MetricsInfoProvider);
            }

            if (infoSettings.AddApplicationInfo)
            {
                info.RegisterProvider(
                    CreateEntry("application-info"),
                    new ApplicationInfoProvider(
                        context.ApplicationIdentity,
                        context.ApplicationLimits,
                        context.ApplicationReplication));
            }

            return(info);
        }
コード例 #2
0
        private DiagnosticInfo BuildDiagnosticInfo(BuildContext context, IHealthTracker healthTracker)
        {
            var infoSettings = infoSettingsCustomization.Customize(new DiagnosticInfoSettings());
            var info         = new DiagnosticInfo();

            if (infoSettings.AddEnvironmentInfo)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.EnvironmentInfo), new EnvironmentInfoProvider(context.Datacenters));
            }

            if (infoSettings.AddSystemMetricsInfo)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.SystemMetrics), context.RegisterDisposable(new SystemMetricsProvider()));
            }

            if (infoSettings.AddLoadedAssembliesInfo)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.LoadedAssemblies), new LoadedAssembliesProvider());
            }

            if (infoSettings.AddHealthChecksInfo)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.HealthChecks), new HealthChecksInfoProvider(healthTracker));
            }

            if (infoSettings.AddConfigurationInfo)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.Configuration), new ConfigurationInfoProvider(context.ConfigurationSource));
            }

            if (infoSettings.AddHerculesSinkInfo && context.HerculesSink is HerculesSink realSink)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.HerculesSink), new HerculesSinkInfoProvider(realSink));
            }

            if (infoSettings.AddApplicationMetricsInfo && context.MetricsInfoProvider != null)
            {
                info.RegisterProvider(CreateEntry(WellKnownDiagnosticInfoProvidersNames.ApplicationMetrics), context.MetricsInfoProvider);
            }

            if (infoSettings.AddApplicationInfo)
            {
                info.RegisterProvider(
                    CreateEntry(WellKnownDiagnosticInfoProvidersNames.ApplicationInfo),
                    new ApplicationInfoProvider(
                        context.ApplicationIdentity,
                        context.ApplicationLimits,
                        context.ApplicationReplication));
            }

            return(info);
        }
コード例 #3
0
        public VostokHealthCheckService(
            [NotNull] IOptions <HealthCheckServiceOptions> options,
            [NotNull] IServiceProvider serviceProvider,
            [NotNull] IHealthTracker vostokTracker,
            [NotNull] Type defaultServiceType,
            [NotNull] List <IDisposable> disposables)
        {
            this.defaultServiceType = defaultServiceType ?? throw new ArgumentNullException(nameof(defaultServiceType));
            this.serviceProvider    = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            this.vostokTracker      = vostokTracker ?? throw new ArgumentNullException(nameof(vostokTracker));
            this.disposables        = disposables ?? throw new ArgumentNullException(nameof(disposables));
            this.options            = (options ?? throw new ArgumentNullException(nameof(options))).Value;

            RegisterMicrosoftChecksInVostokTracker();
        }
コード例 #4
0
        private void ReplaceHealthCheckService(IServiceCollection services, IHealthTracker healthTracker)
        {
            var descriptors         = services.Where(service => service.ServiceType == typeof(HealthCheckService)).ToArray();
            var defaultRegistration = descriptors.First();

            var vostokRegistration = ServiceDescriptor.Describe(
                typeof(HealthCheckService),
                provider => new VostokHealthCheckService(
                    provider.GetRequiredService <IOptions <HealthCheckServiceOptions> >(),
                    provider,
                    healthTracker,
                    defaultRegistration.ImplementationType,
                    disposables),
                ServiceLifetime.Singleton);

            foreach (var descriptor in descriptors)
            {
                services.Remove(descriptor);
            }

            services.Add(vostokRegistration);
        }
コード例 #5
0
ファイル: HealthCheckMetrics.cs プロジェクト: vostok/hosting
        public static IDisposable Measure(IHealthTracker healthTracker, IVostokApplicationMetrics context)
        {
            var metrics = new HealthCheckMetrics(healthTracker, context.Instance.WithTag(WellKnownTagKeys.Component, "VostokHealthChecks"));

            return(healthTracker.ObserveReports().Subscribe(metrics));
        }
コード例 #6
0
ファイル: HealthCheckMetrics.cs プロジェクト: vostok/hosting
        private HealthCheckMetrics(IHealthTracker healthTracker, IMetricContext context)
        {
            this.context = context;

            healthTracker.ObserveReports().Subscribe(this);
        }
コード例 #7
0
 public static void Measure(IHealthTracker healthTracker, IVostokApplicationMetrics context)
 {
     // ReSharper disable once ObjectCreationAsStatement
     new HealthCheckMetrics(healthTracker, context.Instance.WithTag(WellKnownTagKeys.Component, "VostokHealthChecks"));
 }
コード例 #8
0
 public HealthChecksInfoProvider(IHealthTracker healthTracker)
 => this.healthTracker = healthTracker;