C# / .NETDevOpsMisc
C# / .NET
Health checks in .net core
Alexandru Puiu
Alexandru Puiu
October 17, 2019
1 min

Table Of Contents

01
Basic health probe
02
Create health checks
03
Health Checks UI
04
Health Checks as Azure DevOps Release Gates

Monitorama PDX 2016 - Kelsey Hightower - healthz: Stop reverse engineering applications and start monitoring from the inside from Monitorama on Vimeo.


The idea with Health checks is that the application is the best one to know about the state of its components, and how critical each one is. By having the application output its own health information, you don’t need to reinvent the wheel in 3rd party scanners and monitors, trying to do the same type of operations your website does just to make sure everything’s running.

Additionally, health endpoints open up a new world of resilience when used in conjunction with orchestration platforms like Kubernetes, allowing you to build a kind of immune system for your application. Check out the concept of Chaos Engineering from Netflix with a system they call Chaos Monkey https://www.gremlin.com/chaos-monkey/

However, they also provide benefits for teams in earlier stages of automation, but allowing health information from applications and their components to be displayed on a dashboard, or changes in state communicated (ex: via Slack.)

Basic health probe

A health probe is something that checks the health endpoint of a service.

Docker comes with a simple HEALTHCHECK directive that allows you to turn off a faulty container

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

It’s also possible to chain health endpoints with other health endpoint, for example if your microservice depends on another microservice that has a health endpoint.

Create health checks

public class ExampleHealthCheck : IHealthCheck
{
    public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken))
    {
        var healthCheckResultHealthy = true;

        if (healthCheckResultHealthy)
            return Task.FromResult(HealthCheckResult.Healthy("A healthy result."));

        return Task.FromResult(HealthCheckResult.Unhealthy("An unhealthy result."));
    }
}

Source: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-3.0

Health Checks UI


HealthChecksUI provides a great GUI on top of your health checks, when output in a format it expects.

https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks

Health Checks as Azure DevOps Release Gates

https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/extensions/README.md


Tags

devopssecurityperformance
Alexandru Puiu

Alexandru Puiu

Engineer / Security Architect

Systems Engineering advocate, Software Engineer, Security Architect / Researcher, SQL/NoSQL DBA, and Certified Scrum Master with a passion for Distributed Systems, AI and IoT..

Expertise

.NET
RavenDB
Kubernetes

Social Media

githubtwitterwebsite

Related Posts

Authentication in HttpClientFactory
Authentication in Http Client Factory
December 21, 2022
1 min

Subscribe To My Newsletter

I'll only send worthwhile content I think you'll want, less than once a month, and promise to never spam or sell your information!
© 2022, All Rights Reserved.

Quick Links

Get In TouchAbout Me

Social Media