ASP.NET 健康检查不适用于 Blazor 应用程序部署
ASP.NET Healthchecks Not Working on Blazor App Deployment
我有一个 ui Blazor 服务器应用程序并将其部署在 IIS 上。除了健康检查之外,它的所有核心功能都符合预期 运行ning。当我通过 visual studio 运行 Blazor 应用程序时,我在 healthcheck-ui 中得到以下结果:
但是,当我转到已部署应用程序的健康检查 ui 页面时,我看到的是:
如您所见,状态是不健康的,sql 健康检查有 'disappeared' 而端点健康检查似乎有不同的名称?
下面是我的 Startup.cs:
using AjuaBlazorServerApp.HealthChecks;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace AjuaBlazorServerApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddHostedService<PeriodicExecutor>();
services.AddHealthChecks()
.AddCheck<AjuaEndpointHealth>("AjuaEndpoint",null)
.AddSqlServer(Configuration["sqlString"],
healthQuery: "select 1",
failureStatus: HealthStatus.Degraded,
name: "SQL Server");
services.AddHealthChecksUI(opt =>
{
opt.SetEvaluationTimeInSeconds(5); //time in seconds between check
opt.MaximumHistoryEntriesPerEndpoint(60); //maximum history of checks
opt.SetApiMaxActiveRequests(1); //api requests concurrency
opt.AddHealthCheckEndpoint("Ajua API", "/health"); //map health check api
}).AddInMemoryStorage();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddLog4Net("log4net.config");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapHealthChecks("/health", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.
WriteHealthCheckUIResponse
});
endpoints.MapHealthChecksUI();
});
}
}
}
如果我们采用托管应用程序的以下示例 IP 1.1.1.1:80
是否有一些我应该在 Startup.cs 或任何地方设置的设置否则为了解决这个问题?
我找到了解决方案。
基本上在 AddHealthCheckEndpoint
覆盖中添加 /health
前面的主机 ip 和端口。请记住 http
和 https
不可互换,因此请根据您在 IIS 中的配置使用正确的。
services.AddHealthChecksUI(opt =>
{
opt.SetEvaluationTimeInSeconds(5); //time in seconds between check
opt.MaximumHistoryEntriesPerEndpoint(60); //maximum history of checks
opt.SetApiMaxActiveRequests(1); //api requests concurrency
opt.AddHealthCheckEndpoint("Ajua API", "http://1.1.1.1:80/health"); //map health check api
}).AddInMemoryStorage();
我有一个 ui Blazor 服务器应用程序并将其部署在 IIS 上。除了健康检查之外,它的所有核心功能都符合预期 运行ning。当我通过 visual studio 运行 Blazor 应用程序时,我在 healthcheck-ui 中得到以下结果:
但是,当我转到已部署应用程序的健康检查 ui 页面时,我看到的是:
如您所见,状态是不健康的,sql 健康检查有 'disappeared' 而端点健康检查似乎有不同的名称? 下面是我的 Startup.cs:
using AjuaBlazorServerApp.HealthChecks;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace AjuaBlazorServerApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddHostedService<PeriodicExecutor>();
services.AddHealthChecks()
.AddCheck<AjuaEndpointHealth>("AjuaEndpoint",null)
.AddSqlServer(Configuration["sqlString"],
healthQuery: "select 1",
failureStatus: HealthStatus.Degraded,
name: "SQL Server");
services.AddHealthChecksUI(opt =>
{
opt.SetEvaluationTimeInSeconds(5); //time in seconds between check
opt.MaximumHistoryEntriesPerEndpoint(60); //maximum history of checks
opt.SetApiMaxActiveRequests(1); //api requests concurrency
opt.AddHealthCheckEndpoint("Ajua API", "/health"); //map health check api
}).AddInMemoryStorage();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddLog4Net("log4net.config");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapHealthChecks("/health", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.
WriteHealthCheckUIResponse
});
endpoints.MapHealthChecksUI();
});
}
}
}
如果我们采用托管应用程序的以下示例 IP 1.1.1.1:80
是否有一些我应该在 Startup.cs 或任何地方设置的设置否则为了解决这个问题?
我找到了解决方案。
基本上在 AddHealthCheckEndpoint
覆盖中添加 /health
前面的主机 ip 和端口。请记住 http
和 https
不可互换,因此请根据您在 IIS 中的配置使用正确的。
services.AddHealthChecksUI(opt =>
{
opt.SetEvaluationTimeInSeconds(5); //time in seconds between check
opt.MaximumHistoryEntriesPerEndpoint(60); //maximum history of checks
opt.SetApiMaxActiveRequests(1); //api requests concurrency
opt.AddHealthCheckEndpoint("Ajua API", "http://1.1.1.1:80/health"); //map health check api
}).AddInMemoryStorage();