This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the Home repo.
Install-Package Microsoft.AspNet.HealthChecks
//Global.cs
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
HealthCheckHandler.Timeout = TimeSpan.FromSeconds(3);
GlobalHealthChecks.Build(builder =>
builder.WithDefaultCacheDuration(TimeSpan.FromMinutes(1))
.AddUrlCheck("https://github.com")
.AddHealthCheckGroup(
"servers",
group => group.AddUrlCheck("https://google.com")
.AddUrlCheck("https://twitddter.com")
)
.AddHealthCheckGroup(
"memory",
group => group.AddPrivateMemorySizeCheck(1)
.AddVirtualMemorySizeCheck(2)
.AddWorkingSetCheck(1)
)
.AddCheck("thrower", (Func<IHealthCheckResult>)(() => { throw new DivideByZeroException(); }))
.AddCheck("long-running", async cancellationToken => { await Task.Delay(10000, cancellationToken); return HealthCheckResult.Healthy("I ran too long"); })
);
}
}
Install-Package Microsoft.AspNetCore.HealthChecks
//Program.cs
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseHealthChecks("/health", TimeSpan.FromSeconds(3)) // Or to host on a separate port: .UseHealthChecks(port)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// When doing DI'd health checks, you must register them as services of their concrete type
services.AddSingleton<CustomHealthCheck>();
services.AddHealthChecks(checks =>
{
checks.AddUrlCheck("https://github.com")
.AddHealthCheckGroup(
"servers",
group => group.AddUrlCheck("https://google.com")
.AddUrlCheck("https://twitddter.com")
)
.AddHealthCheckGroup(
"memory",
group => group.AddPrivateMemorySizeCheck(1)
.AddVirtualMemorySizeCheck(2)
.AddWorkingSetCheck(1),
CheckStatus.Unhealthy
)
.AddCheck("thrower", (Func<IHealthCheckResult>)(() => { throw new DivideByZeroException(); }))
.AddCheck("long-running", async cancellationToken => { await Task.Delay(10000, cancellationToken); return HealthCheckResult.Healthy("I ran too long"); })
.AddCheck<CustomHealthCheck>("custom");
// Install-Package Microsoft.Extensions.HealthChecks.AzureStorage
// Install-Package Microsoft.Extensions.HealthChecks.SqlServer
// add valid storage account credentials first
checks.AddAzureBlobStorageCheck("accountName", "accountKey");
checks.AddAzureBlobStorageCheck("accountName", "accountKey", "containerName");
checks.AddAzureTableStorageCheck("accountName", "accountKey");
checks.AddAzureTableStorageCheck("accountName", "accountKey", "tableName");
checks.AddAzureFileStorageCheck("accountName", "accountKey");
checks.AddAzureFileStorageCheck("accountName", "accountKey", "shareName");
checks.AddAzureQueueStorageCheck("accountName", "accountKey");
checks.AddAzureQueueStorageCheck("accountName", "accountKey", "queueName");
*/
});
services.AddMvc();
}