Noel
Noel

Reputation: 5399

.net core health checks

See here for how to implement health checks in ASP.net core.

My question is how does on do it for non ASP.net core.

I would think lots of people running apps in docker containers and using the likes of the following in Dockerfile:

HEALTHCHECK CMD curl --fail http://localhost:5000/healthz || exit

But not all apps are web apps, so for no web how do you monitor the health of the app?

Upvotes: 2

Views: 700

Answers (1)

matt_lethargic
matt_lethargic

Reputation: 2796

For none core apps you can just add a new controller and a get method

[RoutePrefix("healthz")]
public class HealthController : ApiController
{
    [HttpGet,Route]
    public IHttpActionResult Index()
    {
        return Ok();
    }
}

This will do the same thing, if you want to check the health of any resources such as databases then you can put code inside the Index method to do these checks first and return a different status code if something is down such as

return InternalServerError();

Upvotes: 3

Related Questions