The CustomChecks Plugin enables custom endpoint monitoring. It allows the developer of an NServiceBus endpoint to define a set of conditions that are checked on endpoint startup or periodically.
These conditions are solution and/or endpoint specific. It is recommended that they include the set of explicit (and implicit) assumptions about what enables the endpoint to function as expected versus what will make the endpoint fail.
For example, custom checks can include checking that a third-party service provider is accessible from the endpoint host, verifying that resources required by the endpoint are above a defined minimum threshold, and more.
There are two types of custom checks: custom checks, and period checks.
Custom check
A custom check is executed once when the endpoint host starts. NServiceBus assembly scanning mechanism detects a class inheriting from CustomCheck
and creates an instance of that class. The check should happen in the constructor for NServiceBus Version 5 and the result needs to be communicated back using either ReportPass
or ReportFailed
methods. For NServiceBus Version 6 the check should happen in the PerformCheck
method and the result needs to be communicated back using either CheckResult.
or CheckResult.
methods.
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.");
}
}
Periodic check
A periodic check is executed at defined intervals. The check happens not in the constructor but in a dedicated PerformCheck
method which returns the check result.
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.");
}
}
PeriodicCheck
class has been deprecated. Inherit from CustomCheck
and provided a TimeSpan
to repeatAfter
in the constructor of the CustomCheck
.Results
The result of a custom check is either success or failure (with a detailed description defined by the developer). This result is sent as a message to the ServiceControl queue and the status will be shown in the ServicePulse UI.
Deprecated NuGet Packages
The following CustomChecks plugin packages have been deprecated and unlisted. If using one of these versions replace package references to use NServiceBus.CustomChecks.
- ServiceControl.Plugin.CustomChecks
- ServiceControl.Plugin.Nsb5.CustomChecks
- ServiceControl.Plugin.Nsb6.CustomChecks
Configuration
Configuration
ServiceControl Queue
Plugins send messages using the defined endpoint transport to ServiceControl. The plugin must be configured with the location of the ServiceControl input queue. This queue is created during the installation of ServiceControl. The queue name is based on the ServiceControl instance name which is visible in the ServiceControl Management utility.
Configure the ServiceControl queue via code:
var endpointConfiguration = new EndpointConfiguration("myendpoint");
endpointConfiguration.CustomCheckPlugin(
serviceControlQueue: "ServiceControl_Queue");
Configure the ServiceControl queue via config:
<appSettings>
<add key="ServiceControl/Queue"
value="particular.servicecontrol@machine" />
</appSettings>
Disabling plugin
var endpointConfiguration = new EndpointConfiguration("myendpoint");
endpointConfiguration.DisableFeature<ServiceControl.Features.CustomChecks>();