Skip to content

WebApi implementation of the health check endpoints for reporting the health of app infrastructure components.

License

Notifications You must be signed in to change notification settings

AndrePostiga/WebApi.HealthChecks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebApi.HealthChecks

CI Build Nuget

WebApi.HealthChecks offers a WebApi implementation of the health check endpoints for reporting the health of app infrastructure components.

The package is available on NuGet

PM> Install-Package WebApi.HealthChecks

Health checks are exposed by an app as HTTP endpoints. Supports two endpoints:

  • GET /health?check=:check where check is optional
  • GET /health/ui?check=:check where check is optional

By default the health check endpoint is created at /health

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.AddHealthChecks(healthEndpoint: "health")
            .Configure(addWarningHeader: true) // optional configuration
            .OverrideResultStatusCodes(unhealthy: HttpStatusCode.InternalServerError) // optional configuration
            .AddCheck("sqlDb", new SqlHealthCheck()) // Singleton instance
            .AddCheck<ICosmosDbCheck>("cosmosDb") // needs to be registered in DependencyResolver
            .AddCheck("lambda", () => new HealthCheckResult(HealthStatus.Healthy, "Lambda check"));
    }
}

Every health check must implement IHealthCheck interface

public interface IHealthCheck
{
    Task<HealthCheckResult> CheckHealthAsync();
}

The framework supports three statuses: Unhealthy , Degraded and Healthy.

GET /health returns json in the following format:

{
  "status": "Degraded",
  "totalResponseTime": 13,
  "entries": {
    "sqlDb": {
      "responseTime": 8,
      "status": "Healthy"
    },
    "cosmosDb": {
      "responseTime": 5,
      "status": "Degraded"
    },
    "lambda": {
      "responseTime": 0,
      "status": "Healthy",
      "description": "Lambda check"
    }
  }
}

The GET /health/ui?check=:check endpoint returns a SVG badge which shows individual status of the service component. For example GET /health/ui?check=cosmosDb will output this image: degraded

About

WebApi implementation of the health check endpoints for reporting the health of app infrastructure components.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.7%
  • ASP.NET 0.3%