public static void WriteHealthCheckData(HealthCheckDto healthcheckdto) { if (healthcheckdto == null) { if (indexOfErrorTime == errorValueArray.Length) { indexOfErrorTime--; } var ms = errorValueArray[indexOfErrorTime++]; timer.Change(ms, ms); Console.WriteLine("Error, Internet connection is not available, " + "next attempt will be made at " + ms / 1000 + " seconds"); } else { Console.WriteLine("IsDbConnected" + " – " + healthcheckdto.IsDbConnected); Console.WriteLine("Version" + " – " + healthcheckdto.Version); Console.WriteLine("Service status" + " – " + healthcheckdto.ServiceStatus); foreach (var item in healthcheckdto.Workers) { Console.WriteLine("– " + item.Name + " Status: " + item.StatusText); } Console.WriteLine(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/error/index"); } app.UseHttpsRedirection(); app.UseSerilogRequestLogging(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseHealthChecks("/health", new HealthCheckOptions { ResponseWriter = async(context, report) => { var response = new HealthCheckDto { Status = report.Status.ToString(), HealthChecks = report.Entries.Select(x => new IndividualHealthCheckDto { Component = x.Key, Status = x.Value.Status.ToString(), Description = x.Value.Description }), HealthCheckDuration = report.TotalDuration }; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(JsonConvert.SerializeObject(response)); } }); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "APIs", pattern: "api/{controller=ApiData}/{action=SaveDataByQuery}/{id?}"); }); }
/// <summary> /// Gets the health check. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public object Get(HealthCheckDto request) { HealthCheck result; switch (request.Scope) { case "monitoring": result = new Monitoring(); break; case "full": result = new Full(); break; default: result = new HealthCheck(); break; } Response.AddHeader("x-node-id", result.NodeId); Response.AddHeader("x-node-status", result.NodeStatus.ToString()); return(result); }
public GetHealthCheckQueryResult(HealthCheckDto healthCheck) { HealthCheck = healthCheck; }