2019-08-13 14:19:27 +08:00
|
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2019-08-13 17:30:56 +08:00
|
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
2019-08-13 14:19:27 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.AspNetCore.Builder
|
2019-08-13 13:39:18 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// BootstrapAdmin 健康检查扩展类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class HealthChecksAppBuilderExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-08-13 14:19:27 +08:00
|
|
|
|
/// 启用健康检查
|
2019-08-13 13:39:18 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="app"></param>
|
2019-08-13 14:19:27 +08:00
|
|
|
|
/// <param name="path"></param>
|
2019-08-13 13:39:18 +08:00
|
|
|
|
/// <returns></returns>
|
2019-08-13 14:19:27 +08:00
|
|
|
|
public static IApplicationBuilder UseBootstrapHealthChecks(this IApplicationBuilder app, PathString path = default)
|
2019-08-13 13:39:18 +08:00
|
|
|
|
{
|
2019-08-13 14:19:27 +08:00
|
|
|
|
if (path == default) path = "/Healths";
|
|
|
|
|
app.UseHealthChecks(path, new HealthCheckOptions()
|
|
|
|
|
{
|
|
|
|
|
ResponseWriter = (context, report) =>
|
|
|
|
|
{
|
|
|
|
|
context.Response.ContentType = "application/json";
|
|
|
|
|
return context.Response.WriteAsync(JsonConvert.SerializeObject(report));
|
2019-08-13 17:30:56 +08:00
|
|
|
|
},
|
|
|
|
|
ResultStatusCodes =
|
|
|
|
|
{
|
|
|
|
|
[HealthStatus.Healthy] = StatusCodes.Status200OK,
|
|
|
|
|
[HealthStatus.Degraded] = StatusCodes.Status200OK,
|
|
|
|
|
[HealthStatus.Unhealthy] = StatusCodes.Status200OK
|
2019-08-13 14:19:27 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2019-08-13 13:39:18 +08:00
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|