/// <summary>
        /// Adds monitoring of ActiveMQ
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="configFactory">Function that produce configuration for monitoring connection <seealso cref="IActiveMqMonitoringConfig"/></param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void AddActiveMqMonitor(this MonitoringOptions options,
                                              Func <IResourceMonitorConfiguration, IServiceProvider, IActiveMqMonitoringConfig> configFactory,
                                              string resourceName = null,
                                              bool isCritical     = true)
        {
            options.AddResourceMonitor((configuration, provider) =>
            {
                var config = configFactory(configuration, provider);

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

                var connectionFactory = new ConnectionFactory()
                {
                    BrokerUri = config.Uri,
                    UserName  = config.User,
                    Password  = config.Password
                };
                return(new ActiveMqPingMonitor(resourceName, connectionFactory, config.QueueName, configuration, provider.GetRequiredService <ILogger <ActiveMqPingMonitor> >(), isCritical));
            });
        }
Пример #2
0
        /// <summary>
        /// Adds the Shutdown monitor.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="resourceName">Name of the resource. Defaults to: Uri.AbsoluteUri.</param>
        /// <param name="configOverride">The configuration override.</param>
        public static void AddShutdownMonitor(
            this MonitoringOptions options,

            string resourceName = null,
            IResourceMonitorConfiguration configOverride = null)
        {
            options.AddResourceMonitor((conf, provider) =>
            {
                var logger = provider.GetRequiredService <ILogger <ShutdownMonitor> >();
                return(new ShutdownMonitor(
                           resourceName ?? "shutdown",
                           provider.GetRequiredService <IShutdownStatusProvider>(),
                           configOverride ?? conf,
                           logger
                           ));
            });
        }
        /// <summary>
        /// Adds monitoring of ActiveMQ
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="url">Url used to connect to ActiveMQ</param>
        /// <param name="queueName">Queue name where to put ping messages</param>
        /// <param name="username">User used to connect to ActiveMQ</param>
        /// <param name="password">Password used to connect to ActiveMQ</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void AddActiveMqMonitor(this MonitoringOptions options,
                                              string url, string queueName, string username, string password,
                                              string resourceName = null,
                                              bool isCritical     = false)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            options.AddResourceMonitor(
                (configuration, provider) => new ActiveMqPingMonitor(resourceName, new ConnectionFactory()
            {
                BrokerUri = new Uri(url),
                UserName  = username,
                Password  = password
            }, queueName, configuration, provider.GetRequiredService <ILogger <ActiveMqPingMonitor> >(), isCritical));
        }
Пример #4
0
        /// <summary>
        /// Adds the sql database monitor to MonitoringOptions
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="dbProvider">Database provider</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
        /// <param name="configOverride">The configuration override.</param>
        public static void AddSqlDbMonitor(
            this MonitoringOptions options,
            IDbConnectionProvider dbProvider,
            string resourceName = null,
            bool isCritical     = true,
            IResourceMonitorConfiguration configOverride = null)
        {
            options.AddResourceMonitor((conf, provider) =>
            {
                var logger = provider.GetRequiredService <ILogger <SqlDbPingMonitor> >();

                return(new SqlDbPingMonitor(
                           dbProvider,
                           logger,
                           configOverride ?? conf,
                           resourceName ?? "SQL Database",
                           isCritical));
            });
        }
Пример #5
0
 /// <summary>
 /// Adds the HTTP monitor.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="healthCheckEndpoint">The health check endpoint.</param>
 /// <param name="resourceName">Name of the resource. Defaults to: Uri.AbsoluteUri.</param>
 /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
 /// <param name="configOverride">The configuration override.</param>
 public static void AddHttpMonitor(
     this MonitoringOptions options,
     Uri healthCheckEndpoint,
     string resourceName = null,
     bool isCritical     = true,
     IResourceMonitorConfiguration configOverride = null)
 {
     resourceName = resourceName ?? healthCheckEndpoint.AbsoluteUri; // Defaults to the AbsoluteUri of the Health Check Endpoint
     options.AddResourceMonitor((conf, provider) =>
     {
         var logger = provider.GetRequiredService <ILogger <HttpResourceMonitor> >();
         return(new HttpResourceMonitor(
                    resourceName,
                    healthCheckEndpoint,
                    new HttpClient(),
                    configOverride ?? conf,
                    logger,
                    isCritical));
     });
 }
Пример #6
0
        /// <summary>
        /// Adds the SQL database stored procedure monitor to MonitoringOptions
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="dbConnectionProvider">Database connection provider.</param>
        /// <param name="schema">DB schema monitored.</param>
        /// <param name="storedProcedureName">Healthcheck stored procedure name (without schema).</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
        /// <param name="configOverride">The configuration override.</param>
        public static void AddSqlDbStoredProcedureMonitor(
            this MonitoringOptions options,
            IDbConnectionProvider dbConnectionProvider,
            string schema,
            string storedProcedureName,
            string resourceName,
            bool isCritical = true,
            IResourceMonitorConfiguration configOverride = null)
        {
            options.AddResourceMonitor((conf, provider) =>
            {
                var logger = provider.GetRequiredService <ILogger <SqlDbStoredProcedureMonitor> >();

                return(new SqlDbStoredProcedureMonitor(
                           dbConnectionProvider,
                           schema,
                           storedProcedureName,
                           logger,
                           configOverride ?? conf,
                           resourceName,
                           isCritical));
            });
        }
        /// <summary>
        /// Adds the redis monitor to MonitoringOptions
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="multiplexer">The multiplexer.</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
        /// <param name="configOverride">The configuration override.</param>
        public static void AddRedisMonitor(
            this MonitoringOptions options,
            IConnectionMultiplexer multiplexer = null,
            string resourceName = "Redis",
            bool isCritical     = true,
            IResourceMonitorConfiguration configOverride = null)
        {
            options.AddResourceMonitor((conf, provider) =>
            {
                var logger  = provider.GetRequiredService <ILogger <RedisPingMonitor> >();
                multiplexer = multiplexer ?? provider.GetService <IConnectionMultiplexer>();
                if (multiplexer == null)
                {
                    throw new InvalidOperationException("A multiplexer is required either as an argument or from the Container.");
                }

                return(new RedisPingMonitor(
                           isCritical,
                           multiplexer,
                           logger,
                           configOverride ?? conf,
                           resourceName));
            });
        }
Пример #8
0
        /// <summary>
        /// Adds the MongoDB monitor to MonitoringOptions
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="mongo">The MongoDB.</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
        /// <param name="configOverride">The configuration override.</param>
        public static void AddMongoDbMonitor(
            this MonitoringOptions options,
            IMongoDatabase mongo = null,
            string resourceName  = "MongoDB",
            bool isCritical      = true,
            IResourceMonitorConfiguration configOverride = null)
        {
            options.AddResourceMonitor((conf, provider) =>
            {
                var logger = provider.GetRequiredService <ILogger <MongoDbPingMonitor> >();
                mongo      = mongo ?? provider.GetService <IMongoDatabase>();
                if (mongo == null)
                {
                    throw new InvalidOperationException("A MongoDB instance is required either as an argument or from the Container.");
                }

                return(new MongoDbPingMonitor(
                           mongo,
                           logger,
                           configOverride ?? conf,
                           resourceName,
                           isCritical));
            });
        }