.NET Core 3.x中的多个运行状况检查终结点

.NET Core 3.x中的多个运行状况检查终结点,.net,asp.net-mvc,asp.net-core,.net-core,.net,Asp.net Mvc,Asp.net Core,.net Core,有没有办法在.NETCore3.x中配置多个healthcheck端点 app.UseEndpoints(endpoints => { endpoints.MapHealthChecks("/health"); }; 这是我目前拥有的,我似乎无法在此基础上配置另一个 在这种情况下,重定向将无法工作,因为其中一个端点将位于防火墙后面。由于HealthChecks是一个普通的中间件,因此您可以始终以与其他普通中间件相同的方式配置管道 例如: //in a sequence way a

有没有办法在.NETCore3.x中配置多个healthcheck端点

app.UseEndpoints(endpoints =>
{
    endpoints.MapHealthChecks("/health");
};
这是我目前拥有的,我似乎无法在此基础上配置另一个


在这种情况下,重定向将无法工作,因为其中一个端点将位于防火墙后面。

由于
HealthChecks
是一个普通的中间件,因此您可以始终以与其他普通中间件相同的方式配置管道

例如:

//in a sequence way
app.UseHealthChecks("/path1");
app.UseHealthChecks("/path2");

// in a branch way: check a predicate function dynamically
app.MapWhen(
    ctx => ctx.Request.Path.StartsWithSegments("/path3") || ctx.Request.Path.StartsWithSegments("/path4"), 
    appBuilder=>{
        appBuilder.UseMiddleware<HealthCheckMiddleware>();
    }
);

// use endpoint routing
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
    endpoints.MapHealthChecks("/health1");
    endpoints.MapHealthChecks("/health2");
});

//以顺序方式
app.usehalthchecks(“/path1”);
app.usehalthchecks(“/path2”);
//以分支方式:动态检查谓词函数
app.MapWhen(
ctx=>ctx.Request.Path.StartsWithSegments(“/path3”)| | ctx.Request.Path.StartsWithSegments(“/path4”),
appBuilder=>{
appBuilder.UseMiddleware();
}
);
//使用端点路由
app.UseEndpoints(端点=>
{
endpoints.MapControllerRoute(
名称:“默认”,
模式:“{controller=Home}/{action=Index}/{id?}”);
endpoints.MapHealthChecks(“/health1”);
端点。MapHealthChecks(“/health2”);
});

不确定拥有多个healthcheck端点的目的是什么

如果要支持不同的“活动性”和“准备就绪性”健康检查,则正确的方法由Microsoft文档“”指示

本质上,它依赖于将标签添加到健康检查中,然后使用这些标签路由到适当的控制器。您不需要指定带有“live”标记的healthcheck,因为您可以直接获得基本的Http测试

在Startup.ConfigureServices()中

在Startup.Configure()中

services.AddHealthChecks()
        .AddCheck("SQLReady", () => HealthCheckResult.Degraded("SQL is degraded!"), tags: new[] { "ready" })
        .AddCheck("CacheReady", () => HealthCheckResult.Healthy("Cache is healthy!"), tags: new[] { "ready" });
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
    endpoints.MapHealthChecks("/health/ready", new HealthCheckOptions()
    {
        Predicate = (check) => check.Tags.Contains("ready"),});

    endpoints.MapHealthChecks("/health/live", new HealthCheckOptions()
    {
        Predicate = (_) => false});
});