feat: 增加健康检查框架
This commit is contained in:
parent
3ef6140cf2
commit
631c1bd549
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.Admin.HealthChecks
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库检查
|
||||
/// </summary>
|
||||
public class DBHealthCheck : IHealthCheck
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步检查方法
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var data = new Dictionary<string, object>();
|
||||
data.Add("Test1", "Test1");
|
||||
data.Add("Test2", "Test2");
|
||||
return Task.FromResult(HealthCheckResult.Healthy("Ok", data));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// BootstrapAdmin 健康检查扩展类
|
||||
/// </summary>
|
||||
public static class HealthChecksAppBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseBootstrapHealthChecks(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseHealthChecks("Healths");
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// 健康检查扩展类
|
||||
/// </summary>
|
||||
public static class HealthChecksBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加 BootstrapAdmin 健康检查
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <returns></returns>
|
||||
public static IHealthChecksBuilder AddBootstrapAdminHealthChecks(this IHealthChecksBuilder builder)
|
||||
{
|
||||
builder.AddCheck<Bootstrap.Admin.HealthChecks.DBHealthCheck>("db");
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,6 +64,7 @@ namespace Bootstrap.Admin
|
|||
services.AddSwagger();
|
||||
services.AddButtonAuthorization();
|
||||
services.AddDemoTask();
|
||||
services.AddHealthChecks().AddBootstrapAdminHealthChecks();
|
||||
services.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
||||
|
@ -107,6 +108,7 @@ namespace Bootstrap.Admin
|
|||
app.UseHttpsRedirection();
|
||||
app.UseResponseCompression();
|
||||
app.UseStaticFiles();
|
||||
app.UseBootstrapHealthChecks();
|
||||
app.UseBootstrapAdminAuthentication(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
|
||||
app.UseOnlineUsers(callback: TraceHelper.Save);
|
||||
app.UseCacheManager();
|
||||
|
|
Loading…
Reference in New Issue