Writing Custom Checks

Component: ServiceControl CustomChecks
NuGet Package NServiceBus.CustomChecks (3.x)
Target NServiceBus Version: 7.x

To create a custom check, create a new custom check class:

public class MyCustomCheck :
    CustomCheck
{
    public MyCustomCheck()
        : base("SomeId-StartUp", "SomeCategory")
    {

    }

    public override Task<CheckResult> PerformCheck()
    {
        if (SomeService.GetStatus())
        {
            return CheckResult.Pass;
        }

        return CheckResult.Failed("Some service is not available.");
    }
}

When the custom check executes, it should return a pass or fail status, and in the case of failure, a descriptive message. This status and descriptive message will be sent to ServiceControl and will appear in the ServicePulse UI and in ServiceControl integration events.

All custom checks are executed when the endpoint starts up. If the optional interval is specified then the custom check will be executed periodically.

public class MyPeriodicCheck :
    CustomCheck
{
    public MyPeriodicCheck()
        : base("SomeId-Periodic", "SomeCategory", TimeSpan.FromSeconds(5))
    {
    }

    public override Task<CheckResult> PerformCheck()
    {
        if (SomeService.GetStatus())
        {
            return CheckResult.Pass;
        }

        return CheckResult.Failed("Some service is not available.");
    }
}
Custom checks are discovered at runtime using assembly scanning. This means they can also be deployed to endpoints as Nuget packages.

Last modified