core monitoring startup - grecosoft/NetFusion GitHub Wiki
Monitoring: Startup Check
An endpoint is also exposed to check if the composite-application has finished starting. Container orchestration services such as Kubernetes can be configured to check if a given microservice has finished starting and can begin receiving requests. This example will insert an intentional 20 second delay within the application plugin-in module.
Add the following method override to the existing ServiceModule class contained within the Examples.Monitoring.App/Plugin/Modules/ directory:
protected override Task OnStartModuleAsync(IServiceProvider services)
{
return Task.Delay(TimeSpan.FromSeconds(20));
}
Expose an endpoint called to determine if the microservice has started. Add the following line to Program.cs file contained within the Examples.Monitoring.WebApi/ directory:
var app = builder.Build();
app.UseSerilogRequestLogging();
app.UseRouting();
app.MapHealthCheck();
app.MapStartupCheck(); // <-- add this line
app.MapControllers();
Execute Example
Complete the following to run the example microservice and send a HTTP Post request to the example controller:
Execute Microservice
cd ./Examples.Monitoring/src/Examples.Montoring.WebApi/
dotnet run
Send Requests
Continue running the following curl command until a HTTP status 200 result code is returned. Until the service is bootstrapped and started, a HTTP status code of 503 will be returned.
curl http://localhost:5007/mgt/startup-check --verbose
Most container orchestration platforms, such as Kubernetes, will only check the startup status after it has deployed a new container running a Microserivce. After the service has indicated that it has started, the status check will not be invoked again. After the microservice has started, Kubernetes will call the health and readiness check endpoints to monitor the service.