예제 #1
0
        public ManagementApiService(IOptions <MassTransitSettings> settings)
        {
            _settings = settings.Value;

            var provider = new HareDuConfigProvider();

            _config = provider.Configure(c =>
            {
                c.Broker(b =>
                {
                    b.ConnectTo(_settings.ManagementEndpoint);
                    b.UsingCredentials(_settings.UserName, _settings.Password);
                    b.TimeoutAfter(TimeSpan.FromSeconds(5));
                });
                c.Diagnostics(y =>
                {
                    y.Probes(z =>
                    {
                        z.SetMessageRedeliveryThresholdCoefficient(0.60M);
                        z.SetSocketUsageThresholdCoefficient(0.60M);
                        z.SetConsumerUtilizationThreshold(0.65M);
                        z.SetQueueHighFlowThreshold(90);
                        z.SetQueueLowFlowThreshold(10);
                        z.SetRuntimeProcessUsageThresholdCoefficient(0.65M);
                        z.SetFileDescriptorUsageThresholdCoefficient(0.65M);
                        z.SetHighConnectionClosureRateThreshold(90);
                        z.SetHighConnectionCreationRateThreshold(60);
                    });
                });
            });
        }
예제 #2
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="settingsFile">The full path of where the configuration settings file is located.</param>
        /// <param name="configSection">The section found within the configuration file.</param>
        /// <returns></returns>
        public static IServiceCollection AddHareDu(this IServiceCollection services, string settingsFile, string configSection)
        {
            var internalConfig = new InternalHareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile(settingsFile, false)
                                           .Build();

            configuration.Bind(configSection, internalConfig);

            HareDuConfig config = ConfigMapper.Map(internalConfig);

            services.AddSingleton(config);
            services.AddSingleton <IBrokerObjectFactory, BrokerObjectFactory>();
            services.AddSingleton <IScanner, Scanner>();
            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();
            services.AddSingleton <IScannerFactory, ScannerFactory>();
            services.AddSingleton <IScannerResultAnalyzer, ScannerResultAnalyzer>();
            services.AddSingleton <ISnapshotFactory>(x => new SnapshotFactory(x.GetService <IBrokerObjectFactory>()));
            services.AddSingleton <ISnapshotWriter, SnapshotWriter>();
            services.AddSingleton <IDiagnosticReportFormatter, DiagnosticReportTextFormatter>();
            services.AddSingleton <IDiagnosticWriter, DiagnosticWriter>();

            return(services);
        }
예제 #3
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="settingsFile">The full path of where the configuration settings file is located.</param>
        /// <param name="configSection">The section found within the configuration file.</param>
        /// <returns></returns>
        public static ContainerBuilder AddHareDu(this ContainerBuilder builder, string settingsFile, string configSection)
        {
            builder.Register(x =>
            {
                var internalConfig = new InternalHareDuConfig();

                IConfiguration configuration = new ConfigurationBuilder()
                                               .AddJsonFile(settingsFile, false)
                                               .Build();

                configuration.Bind(configSection, internalConfig);

                HareDuConfig config = ConfigMapper.Map(internalConfig);

                return(config);
            })
            .SingleInstance();

            builder.RegisterType <BrokerObjectFactory>()
            .As <IBrokerObjectFactory>()
            .SingleInstance();

            builder.RegisterType <Scanner>()
            .As <IScanner>()
            .SingleInstance();

            builder.RegisterType <KnowledgeBaseProvider>()
            .As <IKnowledgeBaseProvider>()
            .SingleInstance();

            builder.RegisterType <ScannerFactory>()
            .As <IScannerFactory>()
            .SingleInstance();

            builder.RegisterType <ScannerResultAnalyzer>()
            .As <IScannerResultAnalyzer>()
            .SingleInstance();

            builder.RegisterType <SnapshotWriter>()
            .As <ISnapshotWriter>()
            .SingleInstance();

            builder.RegisterType <DiagnosticReportTextFormatter>()
            .As <IDiagnosticReportFormatter>()
            .SingleInstance();

            builder.RegisterType <DiagnosticWriter>()
            .As <IDiagnosticWriter>()
            .SingleInstance();

            builder.Register(x => new SnapshotFactory(x.Resolve <IBrokerObjectFactory>()))
            .As <ISnapshotFactory>()
            .SingleInstance();

            return(builder);
        }
예제 #4
0
        public BrokerObjectFactory(HareDuConfig config)
        {
            _client = GetClient(config);
            _cache  = new ConcurrentDictionary <string, object>();

            if (!TryRegisterAll())
            {
                throw new HareDuBrokerObjectInitException("Could not register broker objects.");
            }
        }
예제 #5
0
        public SnapshotFactory(HareDuConfig config)
        {
            _config  = config;
            _factory = new BrokerObjectFactory(_config);
            _cache   = new Dictionary <string, object>();

            if (!TryRegisterAll())
            {
                throw new HareDuSnapshotInitException("Could not register snapshot lenses.");
            }
        }
예제 #6
0
        public bool IsValid(HareDuConfig config)
        {
            if (config.IsNull() ||
                config.Broker.Credentials.IsNull() ||
                string.IsNullOrWhiteSpace(config.Broker.Credentials.Username) ||
                string.IsNullOrWhiteSpace(config.Broker.Credentials.Password) ||
                string.IsNullOrWhiteSpace(config.Broker.Url))
            {
                return(false);
            }

            return(true);
        }
예제 #7
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configurator">Configure Broker and Diagnostic APIs programmatically.</param>
        /// <returns></returns>
        public static ContainerBuilder AddHareDu(this ContainerBuilder builder, Action <HareDuConfigurator> configurator)
        {
            builder.Register(x =>
            {
                HareDuConfig config = configurator.IsNull()
                        ? ConfigCache.Default
                        : new HareDuConfigProvider()
                                      .Configure(configurator);

                return(config);
            })
            .SingleInstance();

            builder.RegisterType <BrokerObjectFactory>()
            .As <IBrokerObjectFactory>()
            .SingleInstance();

            builder.RegisterType <Scanner>()
            .As <IScanner>()
            .SingleInstance();

            builder.RegisterType <KnowledgeBaseProvider>()
            .As <IKnowledgeBaseProvider>()
            .SingleInstance();

            builder.RegisterType <ScannerFactory>()
            .As <IScannerFactory>()
            .SingleInstance();

            builder.RegisterType <ScannerResultAnalyzer>()
            .As <IScannerResultAnalyzer>()
            .SingleInstance();

            builder.RegisterType <SnapshotWriter>()
            .As <ISnapshotWriter>()
            .SingleInstance();

            builder.RegisterType <DiagnosticReportTextFormatter>()
            .As <IDiagnosticReportFormatter>()
            .SingleInstance();

            builder.RegisterType <DiagnosticWriter>()
            .As <IDiagnosticWriter>()
            .SingleInstance();

            builder.Register(x => new SnapshotFactory(x.Resolve <IBrokerObjectFactory>()))
            .As <ISnapshotFactory>()
            .SingleInstance();

            return(builder);
        }
예제 #8
0
        public HareDuConfig Configure(Action <HareDuConfigurator> configurator)
        {
            if (configurator.IsNull())
            {
                return(ConfigCache.Default);
            }

            var impl = new HareDuConfiguratorImpl();

            configurator?.Invoke(impl);

            HareDuConfig config = impl.Settings.Value;

            return(Validate(config) ? config : ConfigCache.Default);
        }
예제 #9
0
        public void Init()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();

            var internalConfig = new InternalHareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile($"{TestContext.CurrentContext.TestDirectory}/appsettings.json", false)
                                           .Build();

            configuration.Bind("HareDuConfig", internalConfig);

            HareDuConfig config = ConfigMapper.Map(internalConfig);

            services.AddSingleton(config);

            _provider = services.BuildServiceProvider();

            var knowledgeBaseProvider = _provider.GetService <IKnowledgeBaseProvider>();

            _probes = new List <DiagnosticProbe>
            {
                new HighConnectionCreationRateProbe(config.Diagnostics, knowledgeBaseProvider),
                new HighConnectionClosureRateProbe(config.Diagnostics, knowledgeBaseProvider),
                new UnlimitedPrefetchCountProbe(knowledgeBaseProvider),
                new ChannelThrottlingProbe(knowledgeBaseProvider),
                new ChannelLimitReachedProbe(knowledgeBaseProvider),
                new BlockedConnectionProbe(knowledgeBaseProvider),
                new QueueGrowthProbe(knowledgeBaseProvider),
                new MessagePagingProbe(knowledgeBaseProvider),
                new RedeliveredMessagesProbe(config.Diagnostics, knowledgeBaseProvider),
                new ConsumerUtilizationProbe(config.Diagnostics, knowledgeBaseProvider),
                new UnroutableMessageProbe(knowledgeBaseProvider),
                new QueueLowFlowProbe(config.Diagnostics, knowledgeBaseProvider),
                new QueueNoFlowProbe(knowledgeBaseProvider),
                new QueueHighFlowProbe(config.Diagnostics, knowledgeBaseProvider),
                new RuntimeProcessLimitProbe(config.Diagnostics, knowledgeBaseProvider),
                new SocketDescriptorThrottlingProbe(config.Diagnostics, knowledgeBaseProvider),
                new NetworkPartitionProbe(knowledgeBaseProvider),
                new MemoryAlarmProbe(knowledgeBaseProvider),
                new DiskAlarmProbe(knowledgeBaseProvider),
                new AvailableCpuCoresProbe(knowledgeBaseProvider),
                new FileDescriptorThrottlingProbe(config.Diagnostics, knowledgeBaseProvider)
            };
        }
예제 #10
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configurator">Configure Broker and Diagnostic APIs programmatically.</param>
        /// <returns></returns>
        public static IServiceCollection AddHareDu(this IServiceCollection services, Action <HareDuConfigurator> configurator)
        {
            HareDuConfig config = configurator.IsNull()
                ? ConfigCache.Default
                : new HareDuConfigProvider()
                                  .Configure(configurator);

            services.AddSingleton(config);
            services.AddSingleton <IBrokerObjectFactory, BrokerObjectFactory>();
            services.AddSingleton <IScanner, Scanner>();
            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();
            services.AddSingleton <IScannerFactory, ScannerFactory>();
            services.AddSingleton <IScannerResultAnalyzer, ScannerResultAnalyzer>();
            services.AddSingleton <ISnapshotFactory>(x => new SnapshotFactory(x.GetService <IBrokerObjectFactory>()));

            return(services);
        }
예제 #11
0
        public ScannerFactory(HareDuConfig config, IKnowledgeBaseProvider kb)
        {
            _config       = config.IsNotNull() ? config : throw new HareDuDiagnosticsException($"{nameof(config)} argument missing.");
            _kb           = kb.IsNotNull() ? kb : throw new HareDuDiagnosticsException($"{nameof(kb)} argument missing.");
            _scannerCache = new ConcurrentDictionary <string, object>();
            _probeCache   = new ConcurrentDictionary <string, DiagnosticProbe>();
            _observers    = new List <IDisposable>();

            if (!TryRegisterAllProbes())
            {
                throw new HareDuDiagnosticsException("Could not register diagnostic probes.");
            }

            if (!TryRegisterAllScanners())
            {
                throw new HareDuDiagnosticsException("Could not register diagnostic scanners.");
            }
        }
예제 #12
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="settingsFile">The full path of where the configuration settings file is located.</param>
        /// <param name="configSection">The section found within the configuration file.</param>
        /// <returns></returns>
        public static ContainerBuilder AddHareDu(this ContainerBuilder builder, string settingsFile = "appsettings.json", string configSection = "HareDuConfig")
        {
            builder.Register(x =>
            {
                HareDuConfig config = new HareDuConfig();

                IConfiguration configuration = new ConfigurationBuilder()
                                               .AddJsonFile(settingsFile, false)
                                               .Build();

                configuration.Bind(configSection, config);

                return(config);
            })
            .SingleInstance();

            builder.RegisterType <BrokerObjectFactory>()
            .As <IBrokerObjectFactory>()
            .SingleInstance();

            builder.RegisterType <Scanner>()
            .As <IScanner>()
            .SingleInstance();

            builder.RegisterType <KnowledgeBaseProvider>()
            .As <IKnowledgeBaseProvider>()
            .SingleInstance();

            builder.RegisterType <ScannerFactory>()
            .As <IScannerFactory>()
            .SingleInstance();

            builder.RegisterType <ScannerResultAnalyzer>()
            .As <IScannerResultAnalyzer>()
            .SingleInstance();

            builder.Register(x => new SnapshotFactory(x.Resolve <IBrokerObjectFactory>()))
            .As <ISnapshotFactory>()
            .SingleInstance();

            return(builder);
        }
예제 #13
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="settingsFile">The full path of where the configuration settings file is located.</param>
        /// <param name="configSection">The section found within the configuration file.</param>
        /// <returns></returns>
        public static IServiceCollection AddHareDu(this IServiceCollection services, string settingsFile = "appsettings.json", string configSection = "HareDuConfig")
        {
            HareDuConfig config = new HareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile(settingsFile, false)
                                           .Build();

            configuration.Bind(configSection, config);

            services.AddSingleton(config);
            services.AddSingleton <IBrokerObjectFactory, BrokerObjectFactory>();
            services.AddSingleton <IScanner, Scanner>();
            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();
            services.AddSingleton <IScannerFactory, ScannerFactory>();
            services.AddSingleton <IScannerResultAnalyzer, ScannerResultAnalyzer>();
            services.AddSingleton <ISnapshotFactory>(x => new SnapshotFactory(x.GetService <IBrokerObjectFactory>()));

            return(services);
        }
예제 #14
0
        public void Init()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();

            var internalConfig = new InternalHareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile($"{TestContext.CurrentContext.TestDirectory}/appsettings.json", false)
                                           .Build();

            configuration.Bind("HareDuConfig", internalConfig);

            HareDuConfig config = ConfigMapper.Map(internalConfig);

            services.AddSingleton(config);

            _provider = services.BuildServiceProvider();
        }
예제 #15
0
 bool Validate(HareDuConfig config) => Validate(config.Broker) && Validate(config.Diagnostics);