Skip to content

Commit

Permalink
新增 健康检查/admin/health,appconfig.json新增healthChecks配置
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Mar 14, 2023
1 parent 2555b1a commit e004c0c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/pkg.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.4.0</Version>
<Version>3.4.1</Version>
<TargetFramework>net7.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
15 changes: 11 additions & 4 deletions src/hosts/ZhonTai.Host/Configs/appconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
//启用枚举属性名
"enableJsonStringEnumConverter": false,
//路由前缀,如配置微服务文档地址:doc/module/swagger
"routePrefix": "swagger",
"routePrefix": "admin/swagger",
//地址
"url": "http://localhost:8000",
"projects": [
{
"name": "中台Admin",
"code": "admin",
"version": "v3.4.0",
"version": "v3.4.1",
"description": ""
}
]
Expand All @@ -46,7 +46,7 @@
//启用
"enable": true,
//路由前缀,如配置微服务文档地址:doc/module
"routePrefix": "",
"routePrefix": "admin",
//页脚
"footer": {
"enable": false,
Expand Down Expand Up @@ -95,5 +95,12 @@
//实现标准标识密码哈希
"passwordHasher": false,
//最大请求大小
"maxRequestBodySize": 104857600
"maxRequestBodySize": 104857600,
//健康检查
"healthChecks": {
//启用
"enable": true,
//访问路径
"path": "/admin/health"
}
}
2 changes: 1 addition & 1 deletion src/hosts/ZhonTai.Host/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"commandName": "Project",
"launchBrowser": true,
"dotnetRunMessages": true,
"launchUrl": "",
"launchUrl": "admin",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down
22 changes: 21 additions & 1 deletion src/platform/ZhonTai.Admin/Core/Configs/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public class AppConfig
/// 最大请求大小
/// </summary>
public long MaxRequestBodySize { get; set; } = 104857600;

/// <summary>
/// 健康检查配置
/// </summary>
public HealthChecksConfig HealthChecks { get; set; } = new HealthChecksConfig();
}

/// <summary>
Expand Down Expand Up @@ -243,7 +248,6 @@ public class ValidateConfig
public bool Permission { get; set; } = true;
}


/// <summary>
/// 验证码配置
/// </summary>
Expand Down Expand Up @@ -297,6 +301,22 @@ public class DynamicApiConfig
public bool FormatResult { get; set; } = true;
}

/// <summary>
/// 健康检查配置
/// </summary>
public class HealthChecksConfig
{
/// <summary>
/// 启用
/// </summary>
public bool Enable { get; set; } = true;

/// <summary>
/// 访问路径
/// </summary>
public string Path { get; set; } = "/health";
}

/// <summary>
/// 应用程序类型
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/platform/ZhonTai.Admin/Core/HostApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Text.Json.Serialization;
using FreeRedis;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;

namespace ZhonTai.Admin.Core;

Expand Down Expand Up @@ -181,6 +183,9 @@ private void ConfigureServices(IServiceCollection services, IWebHostEnvironment

_hostAppOptions?.ConfigurePreServices?.Invoke(hostAppContext);

//健康检查
services.AddHealthChecks();

//雪花漂移算法
var idGeneratorOptions = new IdGeneratorOptions(1) { WorkerIdBitLength = 6 };
_hostAppOptions?.ConfigureIdGenerator?.Invoke(idGeneratorOptions);
Expand Down Expand Up @@ -709,6 +714,16 @@ private void ConfigureMiddleware(WebApplication app, IWebHostEnvironment env, IC
}
#endregion Swagger Api文档

//使用健康检查
if(appConfig.HealthChecks.Enable)
{
app.MapHealthChecks(appConfig.HealthChecks.Path, new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
}

_hostAppOptions?.ConfigurePostMiddleware?.Invoke(hostAppMiddlewareContext);
}
}
1 change: 1 addition & 0 deletions src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.0.0-rc2.7" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.1" />
Expand Down
20 changes: 20 additions & 0 deletions src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e004c0c

Please sign in to comment.