Просмотр исходного кода

新增 健康检查/admin/health,appconfig.json新增healthChecks配置

zhontai 2 лет назад
Родитель
Сommit
e004c0cb8d

+ 1 - 1
build/pkg.props

@@ -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>

+ 11 - 4
src/hosts/ZhonTai.Host/Configs/appconfig.json

@@ -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": ""
       }
     ]
@@ -46,7 +46,7 @@
     //启用
     "enable": true,
     //路由前缀,如配置微服务文档地址:doc/module
-    "routePrefix": "",
+    "routePrefix": "admin",
     //页脚
     "footer": {
       "enable": false,
@@ -95,5 +95,12 @@
   //实现标准标识密码哈希
   "passwordHasher": false,
   //最大请求大小
-  "maxRequestBodySize": 104857600
+  "maxRequestBodySize": 104857600,
+  //健康检查
+  "healthChecks": {
+    //启用
+    "enable": true,
+    //访问路径
+    "path": "/admin/health"
+  }
 }

+ 1 - 1
src/hosts/ZhonTai.Host/Properties/launchSettings.json

@@ -11,7 +11,7 @@
       "commandName": "Project",
       "launchBrowser": true,
       "dotnetRunMessages": true,
-      "launchUrl": "",
+      "launchUrl": "admin",
       "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"
       },

+ 21 - 1
src/platform/ZhonTai.Admin/Core/Configs/AppConfig.cs

@@ -99,6 +99,11 @@ public class AppConfig
     /// 最大请求大小
     /// </summary>
     public long MaxRequestBodySize { get; set; } = 104857600;
+
+    /// <summary>
+    /// 健康检查配置
+    /// </summary>
+    public HealthChecksConfig HealthChecks { get; set; } = new HealthChecksConfig();
 }
 
 /// <summary>
@@ -243,7 +248,6 @@ public class ValidateConfig
     public bool Permission { get; set; } = true;
 }
 
-
 /// <summary>
 /// 验证码配置
 /// </summary>
@@ -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>

+ 15 - 0
src/platform/ZhonTai.Admin/Core/HostApp.cs

@@ -55,6 +55,8 @@ using System.Text.RegularExpressions;
 using Swashbuckle.AspNetCore.SwaggerGen;
 using System.Text.Json.Serialization;
 using FreeRedis;
+using HealthChecks.UI.Client;
+using Microsoft.AspNetCore.Diagnostics.HealthChecks;
 
 namespace ZhonTai.Admin.Core;
 
@@ -181,6 +183,9 @@ public class HostApp
 
         _hostAppOptions?.ConfigurePreServices?.Invoke(hostAppContext);
 
+        //健康检查
+        services.AddHealthChecks();
+
         //雪花漂移算法
         var idGeneratorOptions = new IdGeneratorOptions(1) { WorkerIdBitLength = 6 };
         _hostAppOptions?.ConfigureIdGenerator?.Invoke(idGeneratorOptions);
@@ -709,6 +714,16 @@ public class HostApp
         }
         #endregion Swagger Api文档
 
+        //使用健康检查
+        if(appConfig.HealthChecks.Enable)
+        {
+            app.MapHealthChecks(appConfig.HealthChecks.Path, new HealthCheckOptions()
+            {
+                Predicate = _ => true,
+                ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
+            });
+        }
+
         _hostAppOptions?.ConfigurePostMiddleware?.Invoke(hostAppMiddlewareContext);
     }
 }

+ 1 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj

@@ -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" />

+ 20 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -381,6 +381,11 @@
             最大请求大小
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Core.Configs.AppConfig.HealthChecks">
+            <summary>
+            健康检查配置
+            </summary>
+        </member>
         <member name="T:ZhonTai.Admin.Core.Configs.SwaggerConfig">
             <summary>
             Swagger配置
@@ -561,6 +566,21 @@
             结果格式化
             </summary>
         </member>
+        <member name="T:ZhonTai.Admin.Core.Configs.HealthChecksConfig">
+            <summary>
+            健康检查配置
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Core.Configs.HealthChecksConfig.Enable">
+            <summary>
+            启用
+            </summary>
+        </member>
+        <member name="P:ZhonTai.Admin.Core.Configs.HealthChecksConfig.Path">
+            <summary>
+            访问路径
+            </summary>
+        </member>
         <member name="T:ZhonTai.Admin.Core.Configs.AppType">
             <summary>
             应用程序类型