我已在
Program.cs
中为我的 Blazor 服务器端应用程序设置运行状况检查。我在 Azure 应用服务上运行它。
var healthCheckBuilder = builder.Services.AddHealthChecks()
.AddDbContextCheck<TrackingDbContext>("App Database")
.AddDbContextCheck<UserDbContext>("Identity Database");
if (!string.IsNullOrEmpty(sendGridKey))
healthCheckBuilder.AddSendGrid(sendGridKey, name: "SendGrid", failureStatus: HealthStatus.Degraded);
if (!string.IsNullOrEmpty(blobConnStr))
healthCheckBuilder.AddAzureBlobStorage(blobConnStr,
name: "Azure Blob Storage", failureStatus: HealthStatus.Degraded);
那么我现在该怎么办?我想进行设置,以便 Azure 将重新启动服务和/或启动一个新实例,然后在需要时终止该实例。
如果 Azure 有的话,我还希望仪表板中有一个页面,我可以在其中查看每个服务的运行状况历史记录。
感谢@zori提供MSDOC来配置运行状况检查。
我已通过门户配置了运行状况检查,并使用代码执行以下步骤。
我创建了一个 Blazor 应用程序并通过在
Program.cs
中添加以下代码来配置运行状况检查:
builder.Services.AddHealthChecks();
app
.MapHealthChecks("/health", new HealthCheckOptions()
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
程序.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddHealthChecks();
var app = builder.Build();
app
.MapHealthChecks("/health", new HealthCheckOptions()
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
当地健康检查响应:
部署了应用程序Azure App Service
在门户中配置健康检查:
Monitoring=>Health check
,然后启用运行状况检查并配置路径。导航到实例以检查服务器实例运行状况:
应用程序服务计划中应用程序实例的平均运行状况。