https://github.com/kpol/webapi.healthchecks
WebApi implementation of the health check endpoints for reporting the health of app infrastructure components.
https://github.com/kpol/webapi.healthchecks
health health-check health-checks health-checks-api web web-api
Last synced: 6 months ago
JSON representation
WebApi implementation of the health check endpoints for reporting the health of app infrastructure components.
- Host: GitHub
- URL: https://github.com/kpol/webapi.healthchecks
- Owner: kpol
- License: mit
- Created: 2019-05-28T00:52:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T22:38:28.000Z (over 2 years ago)
- Last Synced: 2024-11-08T03:22:56.807Z (6 months ago)
- Topics: health, health-check, health-checks, health-checks-api, web, web-api
- Language: C#
- Homepage:
- Size: 77.1 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WebApi.HealthChecks
[](https://github.com/kpol/WebApi.HealthChecks/actions)
[](https://www.nuget.org/packages/WebApi.HealthChecks)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**](https://nuget.org/packages/WebApi.HealthChecks)
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("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 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: 