private static void AddSqliteHealthCheck(IHealthChecksBuilder builder, string dbName, PerDatabaseConfiguration config) { if (builder != null) { builder.AddSqlite( sqliteConnectionString: config.ConnectionString, name: dbName, failureStatus: HealthStatus.Unhealthy, tags: new string[] { "db" }); } }
public static void ConfigureSqlite(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI) { services.AddEntityFrameworkSqlite(); services.AddSingleton <IDataBaseModelBuilderOptions>(c => new SqliteModelBuilderOptions()); services.AddDbContextPool <ApplicationDbContext>(builder => { builder.UseSqlite(connectionString, s => s.MigrationsAssembly("IoTSharp.Data.Sqlite")); builder.UseInternalServiceProvider(services.BuildServiceProvider()); } , poolSize); checksBuilder.AddSqlite(connectionString, name: "IoTSharp.Data.Sqlite"); healthChecksUI.AddSqliteStorage("Data Source=health_checks.db"); }
private static IHealthChecksBuilder AddDatabaseCheck(this IHealthChecksBuilder builder, IConfiguration configuration) { var dbServerType = CommonUtilities.GetDatabaseServerTypeFromConfiguration(configuration); var connectionString = CommonUtilities.GetConnectionString(configuration); switch (dbServerType) { case zAppDev.DotNet.Framework.Data.DatabaseManagers.DatabaseServerType.SQLite: return(builder.AddSqlite(connectionString)); case zAppDev.DotNet.Framework.Data.DatabaseManagers.DatabaseServerType.MSSQL: return(builder.AddSqlServer(connectionString)); case zAppDev.DotNet.Framework.Data.DatabaseManagers.DatabaseServerType.MariaDB: return(builder.AddMySql(connectionString)); default: break; } return(builder); }
public static IHealthChecksBuilder AddDatabaseHealthCheck(this IHealthChecksBuilder builder, IConfiguration configuration) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var type = configuration.GetValue <string>("Database:Type"); if (type == DatabaseOptions.Sqlite) { builder.AddSqlite(name: DatabaseOptions.Sqlite, sqliteConnectionString: configuration["Database:ConnectionString"], tags: new string[] { "sqlite" }); } if (type == DatabaseOptions.SqlServer) { builder.AddSqlServer(name: DatabaseOptions.SqlServer, connectionString: configuration["Database:ConnectionString"], tags: new string[] { "sqlserver" }); } return(builder); }
/// <summary> /// 建立HealthChecks服务 /// </summary> /// <param name="builder">HealthChecks服务创建者</param> /// <param name="configuration">应用程序配置</param> /// <returns></returns> protected virtual IHealthChecksBuilder BuildHealthChecks(IHealthChecksBuilder builder, IConfiguration configuration) { //system long providerMemory = configuration["OSharp:HealthChecks:PrivateMemory"].CastTo(1000_000_000L); long virtualMemorySize = configuration["OSharp:HealthChecks:VirtualMemorySize"].CastTo(1000_000_000L); long workingSet = configuration["OSharp:HealthChecks:WorkingSet"].CastTo(1000_000_000L); builder.AddPrivateMemoryHealthCheck(providerMemory); //最大私有内存 builder.AddVirtualMemorySizeHealthCheck(virtualMemorySize); //最大虚拟内存 builder.AddWorkingSetHealthCheck(workingSet); //最大工作内存 OsharpOptions options = configuration.GetOsharpOptions(); //数据库 foreach (var pair in options.DbContexts.OrderBy(m => m.Value.DatabaseType)) { string connectionString = pair.Value.ConnectionString; switch (pair.Value.DatabaseType) { case DatabaseType.SqlServer: builder.AddSqlServer(connectionString, null, pair.Key); break; case DatabaseType.Sqlite: builder.AddSqlite(connectionString, name: pair.Key); break; case DatabaseType.MySql: builder.AddMySql(connectionString, pair.Key); break; case DatabaseType.PostgreSql: builder.AddNpgSql(connectionString, name: pair.Key); break; case DatabaseType.Oracle: builder.AddOracle(connectionString, name: pair.Key); break; default: throw new ArgumentOutOfRangeException($"OSharpOptions中 {pair.Value.DatabaseType} 不受支持"); } } //SMTP if (options.MailSender != null) { var smtp = options.MailSender; builder.AddSmtpHealthCheck(smtpOptions => { smtpOptions.Host = smtp.Host; smtpOptions.LoginWith(smtp.UserName, smtp.Password); }); } //Redis if (options.Redis != null && options.Redis.Enabled) { var redis = options.Redis; builder.AddRedis(redis.Configuration); } //Hangfire if (configuration["OSharp:Hangfire:Enabled"].CastTo(false)) { builder.AddHangfire(hangfireOptions => { hangfireOptions.MinimumAvailableServers = 1; }); } return(builder); }