### Configure HealthChecks.UI Services and Middleware Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Add HealthChecks.UI services and configure the middleware to serve the UI. This example uses in-memory storage. Ensure you have the necessary NuGet packages installed. ```csharp using HealthChecks.UI.Core; using HealthChecks.UI.InMemory.Storage; public class Startup { public void ConfigureServices(IServiceCollection services) { services .AddHealthChecksUI() .AddInMemoryStorage(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app .UseRouting() .UseEndpoints(config => config.MapHealthChecksUI()); } } ``` -------------------------------- ### Install Prometheus Metrics Package Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Install the AspNetCore.HealthChecks.Prometheus.Metrics NuGet package using the package manager console. ```powershell install-package AspNetCore.HealthChecks.Prometheus.Metrics ``` -------------------------------- ### Add RabbitMQ Health Check (Setup Action) Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.RabbitMQ.v6.Tests/HealthChecks.Rabbitmq.approved.txt Adds a RabbitMQ health check using a setup action to configure options. ```APIDOC ## POST /api/health/ready ### Description Adds a RabbitMQ health check to the application's health checks, allowing configuration via a setup action. ### Method POST ### Endpoint /api/health/ready ### Parameters #### Query Parameters - **setup** (Action) - Required - An action to configure the RabbitMQ health check options. - **name** (string) - Optional - A name for the health check. - **failureStatus** (HealthStatus) - Optional - The health status to report if the check fails. - **tags** (IEnumerable) - Optional - A collection of tags to associate with the health check. - **timeout** (TimeSpan) - Optional - The timeout for the health check. ### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) Indicates that the health check has been successfully registered. #### Response Example (No specific response body is defined for this registration action, success is indicated by the absence of errors.) ``` -------------------------------- ### Install All Health Check Packages Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Installs all available health check packages for AspNetCore.Diagnostics.HealthChecks. Use this command in PowerShell to add all packages to your project. ```powershell Install-Package AspNetCore.HealthChecks.ApplicationStatus Install-Package AspNetCore.HealthChecks.ArangoDb Install-Package AspNetCore.HealthChecks.Aws.S3 Install-Package AspNetCore.HealthChecks.Aws.SecretsManager Install-Package AspNetCore.HealthChecks.Aws.Sns Install-Package AspNetCore.HealthChecks.Aws.Sqs Install-Package AspNetCore.HealthChecks.Aws.SystemsManager Install-Package AspNetCore.HealthChecks.Azure.Data.Tables Install-Package AspNetCore.HealthChecks.Azure.IoTHub Install-Package AspNetCore.HealthChecks.Azure.KeyVault.Secrets Install-Package AspNetCore.HealthChecks.Azure.Messaging.EventHubs Install-Package AspNetCore.HealthChecks.Azure.Storage.Blobs Install-Package AspNetCore.HealthChecks.Azure.Storage.Files.Shares Install-Package AspNetCore.HealthChecks.Azure.Storage.Queues Install-Package AspNetCore.HealthChecks.AzureApplicationInsights Install-Package AspNetCore.HealthChecks.AzureDigitalTwin Install-Package AspNetCore.HealthChecks.AzureKeyVault Install-Package AspNetCore.HealthChecks.AzureSearch Install-Package AspNetCore.HealthChecks.AzureServiceBus Install-Package AspNetCore.HealthChecks.AzureStorage Install-Package AspNetCore.HealthChecks.ClickHouse Install-Package AspNetCore.HealthChecks.Consul Install-Package AspNetCore.HealthChecks.CosmosDb Install-Package AspNetCore.HealthChecks.Dapr Install-Package AspNetCore.HealthChecks.DocumentDb Install-Package AspNetCore.HealthChecks.DynamoDB Install-Package AspNetCore.HealthChecks.Elasticsearch Install-Package AspNetCore.HealthChecks.EventStore Install-Package AspNetCore.HealthChecks.EventStore.gRPC Install-Package AspNetCore.HealthChecks.Gcp.CloudFirestore Install-Package AspNetCore.HealthChecks.Gremlin Install-Package AspNetCore.HealthChecks.Hangfire Install-Package AspNetCore.HealthChecks.IbmMQ Install-Package AspNetCore.HealthChecks.InfluxDB Install-Package AspNetCore.HealthChecks.Kafka Install-Package AspNetCore.HealthChecks.Kubernetes Install-Package AspNetCore.HealthChecks.Milvus Install-Package AspNetCore.HealthChecks.MongoDb Install-Package AspNetCore.HealthChecks.MySql Install-Package AspNetCore.HealthChecks.Nats Install-Package AspNetCore.HealthChecks.Network Install-Package AspNetCore.HealthChecks.Npgsql Install-Package AspNetCore.HealthChecks.OpenIdConnectServer Install-Package AspNetCore.HealthChecks.Oracle Install-Package AspNetCore.HealthChecks.Qdrant Install-Package AspNetCore.HealthChecks.RabbitMQ Install-Package AspNetCore.HealthChecks.RavenDB Install-Package AspNetCore.HealthChecks.Redis Install-Package AspNetCore.HealthChecks.SendGrid Install-Package AspNetCore.HealthChecks.SignalR Install-Package AspNetCore.HealthChecks.Solr Install-Package AspNetCore.HealthChecks.SqLite Install-Package AspNetCore.HealthChecks.SqlServer Install-Package AspNetCore.HealthChecks.SurrealDb Install-Package AspNetCore.HealthChecks.System Install-Package AspNetCore.HealthChecks.Uris ``` -------------------------------- ### Add RabbitMQ Health Check (Service Provider Setup Action) Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.RabbitMQ.v6.Tests/HealthChecks.Rabbitmq.approved.txt Adds a RabbitMQ health check using a setup action that has access to the service provider. ```APIDOC ## POST /api/health/ready ### Description Adds a RabbitMQ health check to the application's health checks, allowing configuration via a setup action that can resolve services. ### Method POST ### Endpoint /api/health/ready ### Parameters #### Query Parameters - **setup** (Action) - Required - An action to configure the RabbitMQ health check options, with access to the service provider. - **name** (string) - Optional - A name for the health check. - **failureStatus** (HealthStatus) - Optional - The health status to report if the check fails. - **tags** (IEnumerable) - Optional - A collection of tags to associate with the health check. - **timeout** (TimeSpan) - Optional - The timeout for the health check. ### Request Body This endpoint does not have a request body. ### Response #### Success Response (200) Indicates that the health check has been successfully registered. #### Response Example (No specific response body is defined for this registration action, success is indicated by the absence of errors.) ``` -------------------------------- ### Add Kafka Health Check with Setup Action Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Kafka.Tests/HealthChecks.Kafka.approved.txt Extension method to add Kafka health checks using a setup action for Confluent.Kafka.ProducerConfig. Defaults to 'healthchecks-topic'. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class KafkaHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddKafka(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action setup, string topic = "healthchecks-topic", string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### Install Azure Digital Twin Health Check Package (CLI) Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/src/HealthChecks.AzureDigitalTwin/README.md Use the .NET CLI to add the Azure Digital Twin health check package to your project. ```bash dotnet add package AspNetCore.HealthChecks.AzureDigitalTwin ``` -------------------------------- ### Install HealthChecks Publisher Packages Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Use the NuGet package manager to install the desired HealthChecks publisher packages for your project. ```powershell install-package AspNetcore.HealthChecks.Publisher.ApplicationInsights install-package AspNetcore.HealthChecks.Publisher.CloudWatch install-package AspNetcore.HealthChecks.Publisher.Datadog install-package AspNetcore.HealthChecks.Publisher.Prometheus install-package AspNetcore.HealthChecks.Publisher.Seq ``` -------------------------------- ### Add Ssl Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Network.Tests/HealthChecks.Network.approved.txt Use this to add an Ssl health check. Configure options using the setup action. ```csharp public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddSslHealthCheck(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } ``` -------------------------------- ### Configure UI Paths for HealthChecks UI Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/ui-docker.md Customize the UI, API, and resources paths for the HealthChecks UI using environment variables. This example sets the UI path to '/healthchecks', resources to '/static', and API to '/health-api'. ```bash docker run -e ui_path=/healthchecks-e ui_resources_path=/static -e ui_api_path=/health-api -p 5000:80 xabarilcoding/healthchecksui:latest ``` -------------------------------- ### Get HealthCheck Resource Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/k8s-operator.md Verify the creation of the HealthCheck resource in the specified namespace. ```bash kubectl get healthcheck -n demo ``` -------------------------------- ### Add Tcp Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Network.Tests/HealthChecks.Network.approved.txt Use this to add a Tcp health check. Configure options using the setup action. ```csharp public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddTcpHealthCheck(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } ``` -------------------------------- ### AddAzureKeyVault Health Check Extension (Service Provider Setup) Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.AzureKeyVault.Tests/HealthChecks.AzureKeyVault.approved.txt Adds an Azure Key Vault health check to the specified IHealthChecksBuilder, allowing the setup action to resolve services from the IServiceProvider. This overload is useful for more complex configurations. ```csharp public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureKeyVault(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Uri keyVaultServiceUri, Azure.Core.TokenCredential credential, System.Action setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } ``` -------------------------------- ### Get Minikube Service URL Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md If using Minikube, this command retrieves the URL for the web application service, which is exposed via a NodePort. ```bash minikube service webapp-service --url ``` -------------------------------- ### AddSolr Health Check Extension Method (Action Setup) Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Solr.Tests/HealthChecks.Solr.approved.txt Adds a Solr health check to the specified IHealthChecksBuilder using an action to configure SolrOptions. Useful for complex configurations. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class SolrHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddSolr(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### Configure Network Health Checks Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Implement network health checks for TCP ports, DNS resolution, SMTP, SSL certificates, and SFTP. Ensure the AspNetCore.HealthChecks.Network package is installed. ```csharp // Install: Install-Package AspNetCore.HealthChecks.Network services.AddHealthChecks() // TCP port connectivity .AddTcpHealthCheck(options => { options.AddHost("api.example.com", 443); options.AddHost("database.internal", 5432); }, name: "tcp-endpoints") // DNS resolution .AddDnsResolveHealthCheck(options => { options.ResolveHost("api.example.com"); options.ResolveHost("cdn.example.com"); }, name: "dns-resolution") // SMTP server .AddSmtpHealthCheck(options => { options.Host = "smtp.example.com"; options.Port = 587; options.ConnectionType = SmtpConnectionType.TLS; }, name: "smtp") // SSL certificate expiration .AddSslHealthCheck(options => { options.AddHost("example.com", 443, 30); // Alert 30 days before expiry }, name: "ssl-cert") // SFTP connectivity .AddSftpHealthCheck(options => { options.Host = "sftp.example.com"; options.Port = 22; options.UserName = "user"; options.Password = "password"; }, name: "sftp"); ``` -------------------------------- ### Configure Readiness Probe Endpoint Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md Create an HTTP endpoint at '/ready' to indicate service readiness. This endpoint checks if all dependencies tagged as 'services' are healthy. ```csharp app.UseHealthChecks("/ready", new HealthCheckOptions { Predicate = r => r.Tags.Contains("services") }); ``` -------------------------------- ### Register Custom Stylesheet in Health Checks UI Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/styles-branding.md Register your custom stylesheet in the UseHealthChecksUI setup action to customize the UI. This example shows how to add 'dotnet.css'. ```csharp app .UseRouting() .UseEndpoints(config => { config.MapHealthChecksUI(setup => { setup.AddCustomStylesheet("dotnet.css"); }); }); ``` -------------------------------- ### Add CloudWatch Publisher to HealthChecks Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Publisher.CloudWatch.Tests/HealthChecks.Publisher.CloudWatch.approved.txt Extension method to add the CloudWatch publisher to the ASP.NET Core HealthChecks. Configure the CloudWatch options using the provided setup action. Ensure the necessary AWS SDK packages are installed. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class CloudWatchHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCloudWatchPublisher(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup = null) { } } } ``` -------------------------------- ### Build Docker Image Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md Build a Docker image for the ASP.NET Core application. Ensure you are in the project's root directory. ```bash docker build -t webapp . -f WebApp/Dockerfile ``` -------------------------------- ### Create Demo Namespace Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/k8s-operator.md Use this command to create a namespace for your health checks. ```bash kubectl create ns demo ``` -------------------------------- ### Scale Deployment to Zero Replicas Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md Use this command to scale down a deployment to zero replicas. This is used to test the readiness probe by ensuring no pods are available to serve traffic. ```bash kubectl scale deployment sqlserver --replicas=0 ``` -------------------------------- ### Apply Kubernetes Configurations Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md Apply the Kubernetes infrastructure and deployment configurations. These files define the services and deployments for SQL Server, Redis, and the web application. ```bash kubectl apply -f infra.yml ``` ```bash kubectl apply -f deployment.yml ``` -------------------------------- ### Configure HealthChecks UI with setupSettings Method Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Programmatically configure health checks, webhooks, and database connections using the `AddHealthChecksUI` method. This allows for dynamic endpoint and webhook registration. ```csharp services .AddHealthChecksUI(setupSettings: setup => { setup.AddHealthCheckEndpoint("endpoint1", "http://localhost:8001/healthz"); setup.AddHealthCheckEndpoint("endpoint2", "http://remoteendpoint:9000/healthz"); setup.AddWebhookNotification("webhook1", uri: "http://httpbin.org/status/200?code=ax3rt56s", payload: "{...}"); }) .AddSqlServer("connectionString"); ``` -------------------------------- ### SFTP Configuration Builder Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Network.Tests/HealthChecks.Network.approved.txt Builder for creating SFTP configurations. ```APIDOC ## SFTP Configuration Builder ### Description A builder class for constructing SFTP connection configurations. ### Constructor - **SftpConfigurationBuilder**(string host, int port, string userName) ### Methods #### AddPasswordAuthentication Configures password-based authentication. - **password** (string) - Required - The password for authentication. #### AddPrivateKeyAuthentication Configures private key authentication. - **privateKey** (Renci.SshNet.PrivateKeyFile) - Required - The private key file. #### AddPrivateKeyAuthentication Configures private key authentication with a passphrase. - **privateKey** (string) - Required - The private key content. - **passphrase** (string) - Required - The passphrase for the private key. #### Build Builds the SFTP configuration. #### CreateFileOnConnect Specifies a file to create upon successful connection. - **remoteFilePath** (string) - Required - The path to the remote file. ### Example Usage ```csharp // Example of building SFTP configuration with password authentication var sftpConfig = new HealthChecks.Network.SftpConfigurationBuilder("sftp.example.com", 22, "user") .AddPasswordAuthentication("password") .CreateFileOnConnect("/home/user/test.txt") .Build(); ``` ``` -------------------------------- ### Azure Digital Twin Model Health Check Failure Response Example Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/src/HealthChecks.AzureDigitalTwin/README.md Example JSON response when the Azure Digital Twin model health check detects unregistered models. The 'unregistered' field lists the models not found in the Digital Twin. ```json azuredigitaltwinmodels: { data: { unregistered: [ "my:dt:definition_b;1" ] }, description: "The digital twin is out of sync with the models provided", duration: "00:00:17.6056085", exception: null, status: 1, tags: [ "ready" ] } ``` -------------------------------- ### Create Azure Container Instance with Connection String Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/ui-docker.md Use this command to deploy HealthChecksUI to Azure Container Instances, configuring it to use Azure App Configuration via a connection string. ```bash az container create --resource-group group-name --name container-name -e 'AAC_Enabled=true' 'AAC_Label=HealthChecksConfig' 'AAC_ConnectionString=Endpoint={your_connectionstring}' --image xabarilcoding/healthchecksui:latest --dns-name-label dns-checks --ports 80 ``` -------------------------------- ### Enable Kubernetes Discovery Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/k8s-ui-discovery.md Enable the Kubernetes discovery service and configure essential parameters like the health check path and service labels in appsettings.json. ```json { "HealthChecksUI": { "KubernetesDiscoveryService": { "Enabled": true, "HealthPath": "healthz", "ServicesLabel": "HealthChecks", "ServicesPathAnnotation": "HealthChecksPath", "ServicesPortAnnotation": "HealthChecksPort", "ServicesSchemeAnnotation": "HealthChecksScheme" } } } ``` -------------------------------- ### Add Smtp Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Network.Tests/HealthChecks.Network.approved.txt Use this to add an Smtp health check. Configure options using the setup action. ```csharp public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddSmtpHealthCheck(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } ``` -------------------------------- ### Kubernetes Readiness Probe Configuration Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md Defines the readiness probe for the web application deployment. This probe checks the '/ready' endpoint to determine if the application's dependencies (SQL Server, Redis) are ready to serve traffic. If the probe fails, Kubernetes will not send traffic to this pod. ```yaml readinessProbe: httpGet: path: /ready port: 80 scheme: HTTP initialDelaySeconds: 10 periodSeconds: 15 ``` -------------------------------- ### Add DNS Resolve Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Network.Tests/HealthChecks.Network.approved.txt Adds a DNS resolve health check to the specified IHealthChecksBuilder. Requires a setup action for DnsResolveOptions. ```csharp public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddDnsResolveHealthCheck(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null) { } ``` -------------------------------- ### Configure Kubernetes Liveness and Readiness Probes Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Set up distinct health check endpoints for Kubernetes liveness and readiness probes. Use tags to filter checks for specific probe types. Ensure the Kubernetes deployment.yaml is configured to use these endpoints. ```csharp services.AddHealthChecks() // Self-check for liveness (always returns healthy unless app is crashed) .AddCheck("self", () => HealthCheckResult.Healthy(), tags: new[] { "live" }) // Dependencies for readiness .AddSqlServer( Configuration["ConnectionStrings:Sql"], tags: new[] { "ready", "db" }) .AddRedis( Configuration["ConnectionStrings:Redis"], tags: new[] { "ready", "cache" }) .AddRabbitMQ( tags: new[] { "ready", "messaging" }); public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseEndpoints(endpoints => { // Liveness probe - checks only app is running endpoints.MapHealthChecks("/health/live", new HealthCheckOptions { Predicate = check => check.Tags.Contains("live") }); // Readiness probe - checks all dependencies endpoints.MapHealthChecks("/health/ready", new HealthCheckOptions { Predicate = check => check.Tags.Contains("ready") }); }); } ``` ```yaml spec: containers: - name: myapp livenessProbe: httpGet: path: /health/live port: 80 initialDelaySeconds: 10 periodSeconds: 15 readinessProbe: httpGet: path: /health/ready port: 80 initialDelaySeconds: 10 periodSeconds: 15 ``` -------------------------------- ### Disable Database Migrations for HealthChecks UI Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Disable automatic database migrations for the HealthChecks UI. This can be done via the setup method or configuration. ```csharp services .AddHealthChecksUI(setup => setup.DisableDatabaseMigrations()) .AddInMemoryStorage(); ``` ```json "HealthChecksUI": { "DisableMigrations": true } ``` -------------------------------- ### Configure Health Checks UI with In-Memory Storage Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Set up the Health Checks UI by adding it to services and configuring its behavior, such as evaluation time and history entries. Use AddInMemoryStorage for simple persistence or choose other storage providers like SQL Server, PostgreSQL, MySQL, or SQLite for production environments. Register the UI endpoints in the application's Configure method. ```csharp // Install: Install-Package AspNetCore.HealthChecks.UI // Install: Install-Package AspNetCore.HealthChecks.UI.InMemory.Storage public void ConfigureServices(IServiceCollection services) { services .AddHealthChecksUI(setup => { setup.SetEvaluationTimeInSeconds(10); setup.MaximumHistoryEntriesPerEndpoint(50); setup.SetApiMaxActiveRequests(3); setup.AddHealthCheckEndpoint("API", "http://localhost:5000/healthz"); setup.AddHealthCheckEndpoint("Background Jobs", "http://localhost:5001/health"); }) .AddInMemoryStorage(); // Or use persistent storage: // .AddSqlServerStorage("connectionString"); // .AddPostgreSqlStorage("connectionString"); // .AddMySqlStorage("connectionString"); // .AddSqliteStorage("Data Source=healthchecks.db"); } public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapHealthChecksUI(setup => { setup.UIPath = "/health-ui"; setup.ApiPath = "/health-ui-api"; setup.AddCustomStylesheet("custom-healthcheck.css"); }); }); } ``` -------------------------------- ### Add DNS Resolve Host Count Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Network.Tests/HealthChecks.Network.approved.txt Adds a DNS resolve host count health check. Accepts an optional setup action for DnsResolveCountOptions. ```csharp public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddDnsResolveHostCountHealthCheck(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null) { } ``` -------------------------------- ### Configure UI with Storage Provider Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/ui-changelog.md Configure the storage provider for the Health Checks UI. This is a breaking change from previous versions that used SQLite internally. ```csharp builder.Services.AddHealthChecksUI().AddSqlServerStorage("connectionString"); ``` -------------------------------- ### Add RavenDB Health Check to ASP.NET Core Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.RavenDb.Tests/HealthChecks.RavenDB.approved.txt Use the AddRavenDB extension method to register RavenDB health checks. Configure options via a setup action. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class RavenDBHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddRavenDB(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### Configure UI API and Webhooks HTTP Client Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/ui-changelog.md Expose actions to configure the HTTP client used for the UI API and Webhooks. This allows for custom client configurations. ```csharp setup.ConfigureHttpClients(clientBuilder); ``` -------------------------------- ### Add URI Health Checks Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Configures health checks for HTTP/HTTPS endpoints, supporting custom request configurations and response handling. Ensure the relevant NuGet package is installed. ```csharp // Install: Install-Package AspNetCore.HealthChecks.Uris services.AddHealthChecks() // Simple URI check .AddUrlGroup(new Uri("https://api.example.com/health"), name: "external-api") // Multiple URIs as a group .AddUrlGroup(options => { options.AddUri(new Uri("https://api1.example.com/health"), setup => { setup.UseGet(); setup.ExpectHttpCode(200); }); options.AddUri(new Uri("https://api2.example.com/health"), setup => { setup.UseGet(); setup.AddCustomHeader("X-Api-Key", "secret"); }); }, name: "api-cluster") // URI with POST and body .AddUrlGroup(options => { options.AddUri(new Uri("https://api.example.com/validate"), setup => { setup.UsePost(); setup.UseContent("{\"test\": true}", "application/json"); setup.ExpectHttpCodes(200, 201); }); }, name: "validation-endpoint") // With custom HttpClient configuration .AddUrlGroup(new Uri("https://secure.example.com"), name: "secured-endpoint", configureClient: (sp, client) => { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "token"); client.Timeout = TimeSpan.FromSeconds(10); }); ``` -------------------------------- ### Custom Branding with Volume Mount and Environment Variable Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/ui-docker.md Configure custom branding for the HealthChecks UI by mounting a local CSS file into the container and specifying its path via an environment variable. This requires a CSS file at `/c/temp/css/dotnet.css`. ```bash docker run -v /c/temp/css:/app/css -e ui_stylesheet=/app/css/dotnet.css -p 5000:80 xabarilcoding/healthchecksui:latest ``` -------------------------------- ### Add Consul Health Check to ASP.NET Core Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Consul.Tests/HealthChecks.Consul.approved.txt Register Consul health checks in your ASP.NET.Core application. Use the `AddConsul` extension method with optional configuration and setup actions. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class ConsulHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddConsul(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### Configure HealthChecks in ASP.NET Core Startup Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/k8s-operator.md Sets up health checks in the ASP.NET Core application's services. Includes adding a process memory check and a self-check. ```csharp using HealthChecks.UI.Client; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace hc_website { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddRouting() .AddHealthChecks() .AddProcessAllocatedMemoryHealthCheck(maximumMegabytesAllocated: 50) .AddCheck("self", () => HealthCheckResult.Healthy()); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapHealthChecks("/health", new HealthCheckOptions { Predicate = r => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); }); } } } ``` -------------------------------- ### Configure Default Webhook Notification by Code Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/webhooks.md Set up a webhook notification using C# code with default failure and description messages. This is a simpler approach for basic notification needs. ```csharp setup.AddWebhookNotification("webhook1", uri: "https://healthchecks.requestcatcher.com/", payload: "{ message: \"Webhook report for [[LIVENESS]]: [[FAILURE]] - Description: [[DESCRIPTIONS]]\"}", restorePayload: "{ message: \"[[LIVENESS]] is back to life\"}"); ``` -------------------------------- ### Add System Health Checks Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Configures health checks for disk storage, private memory, virtual memory, Windows services, and processes. Ensure the relevant NuGet package is installed. ```csharp // Install: Install-Package AspNetCore.HealthChecks.System services.AddHealthChecks() // Disk storage check .AddDiskStorageHealthCheck(options => { options.AddDrive("C:\\", minimumFreeMegabytes: 5000); options.AddDrive("D:\\", minimumFreeMegabytes: 10000); }, name: "disk-storage") // Private memory check .AddPrivateMemoryHealthCheck( maximumMemoryBytes: 1024L * 1024L * 1024L, // 1 GB name: "private-memory") // Virtual memory check .AddVirtualMemorySizeHealthCheck( maximumMemoryBytes: 2L * 1024L * 1024L * 1024L, // 2 GB name: "virtual-memory") // Windows service check (Windows only) .AddWindowsServiceHealthCheck( serviceName: "W3SVC", name: "iis-service") // Process health check .AddProcessHealthCheck( processName: "sqlservr", name: "sql-process"); ``` -------------------------------- ### Label Kubernetes Service for Discovery Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/k8s-ui-discovery.md Use this command to label a Kubernetes service for discovery. Ensure the label value matches your configured ServiceLabel. ```bash kubectl label service service-name HealthChecks=true ``` -------------------------------- ### Add Hangfire Health Check Extension Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Hangfire.Tests/HealthChecks.Hangfire.approved.txt Extension method to add Hangfire health checks to an IHealthChecksBuilder. Allows for custom setup actions, names, failure statuses, tags, and timeouts. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class HangfireHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddHangfire(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### Configure Services with Dependency Injected IConnection Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/src/HealthChecks.Rabbitmq/README.md Configure services to use a singleton IConnection instance for the RabbitMQ health check. This is recommended for long-lived connections. ```csharp public void ConfigureServices(IServiceCollection services) { services .AddSingleton(sp => { var factory = new ConnectionFactory { Uri = new Uri("amqps://user:pass@host/vhost"), }; return factory.CreateConnectionAsync().GetAwaiter().GetResult(); }) .AddHealthChecks() .AddRabbitMQ(); } ``` -------------------------------- ### Add DynamoDB Health Check to ASP.NET Core Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.DynamoDb.Tests/HealthChecks.DynamoDb.approved.txt Extension method to add DynamoDB health checks to the ASP.NET Core health checks builder. Allows custom setup and configuration. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class DynamoDbHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddDynamoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### AddRabbitMQ Health Check Extension Methods Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.RabbitMQ.v6.Tests/HealthChecks.Rabbitmq.approved.txt Extension methods for IHealthChecksBuilder to add RabbitMQ health checks. Supports various configuration methods including connection string, URI, and setup actions. ```csharp namespace Microsoft.Extensions.DependencyInjection { public static class RabbitMQHealthCheckBuilderExtensions { public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddRabbitMQ(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddRabbitMQ(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddRabbitMQ(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? setup, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddRabbitMQ(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string rabbitConnectionString, RabbitMQ.Client.SslOption? sslOption = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddRabbitMQ(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Uri rabbitConnectionString, RabbitMQ.Client.SslOption? sslOption = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } ``` -------------------------------- ### Configure Health Checks UI via appsettings.json Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Define health check endpoints, webhook configurations, and UI settings using a JSON configuration file for simplified deployment management. ```json { "HealthChecksUI": { "HealthChecks": [ { "Name": "Orders API", "Uri": "http://orders-api:80/healthz" }, { "Name": "Inventory Service", "Uri": "http://inventory:80/healthz" } ], "Webhooks": [ { "Name": "Slack", "Uri": "https://hooks.slack.com/services/YOUR/WEBHOOK/URL", "Payload": "{\"text\":\"Health Check [[LIVENESS]] is failing: [[FAILURE]]. [[DESCRIPTIONS]]\",\"channel\":\"#alerts\"}", "RestoredPayload": "{\"text\":\"Health Check [[LIVENESS]] is now healthy.\",\"channel\":\"#alerts\"}" }, { "Name": "Teams", "Uri": "https://outlook.office.com/webhook/", "Payload": "{\"@type\":\"MessageCard\",\"themeColor\":\"FF0000\",\"title\":\"[[LIVENESS]] Failed\",\"text\":\"[[FAILURE]]\"}" } ], "EvaluationTimeInSeconds": 30, "MinimumSecondsBetweenFailureNotifications": 300, "DisableMigrations": false } } ``` -------------------------------- ### Check Kubernetes Pod Status Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/kubernetes-liveness.md Verify that all Kubernetes pods, including the web application, SQL Server, and Redis, are running and ready. ```bash kubectl get pods ``` -------------------------------- ### Settings Class for Health Check Configuration Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.UI.Tests/HealthChecks.UI.approved.txt Provides methods to configure health check endpoints, webhook notifications, HTTP client settings, and other advanced options. Use this to customize the health check setup. ```csharp namespace HealthChecks.UI.Configuration { public class Settings { public Settings() { } public HealthChecks.UI.Configuration.Settings AddHealthCheckEndpoint(string name, string uri) { } public HealthChecks.UI.Configuration.Settings AddWebhookNotification(string name, string uri, string payload, string restorePayload = "", System.Func? shouldNotifyFunc = null, System.Func? customMessageFunc = null, System.Func? customDescriptionFunc = null) { } public HealthChecks.UI.Configuration.Settings ConfigureApiEndpointHttpclient(System.Action apiEndpointHttpClientconfig) { } public HealthChecks.UI.Configuration.Settings ConfigureWebhooksEndpointHttpclient(System.Action webhooksEndpointHttpClientconfig) { } public HealthChecks.UI.Configuration.Settings DisableDatabaseMigrations() { } public HealthChecks.UI.Configuration.Settings MaximumHistoryEntriesPerEndpoint(int maxValue) { } public HealthChecks.UI.Configuration.Settings SetApiMaxActiveRequests(int apiMaxActiveRequests) { } public HealthChecks.UI.Configuration.Settings SetEvaluationTimeInSeconds(int seconds) { } public HealthChecks.UI.Configuration.Settings SetHeaderText(string text) { } public HealthChecks.UI.Configuration.Settings SetMinimumSecondsBetweenFailureNotifications(int seconds) { } public HealthChecks.UI.Configuration.Settings SetNotifyUnHealthyOneTimeUntilChange() { } public HealthChecks.UI.Configuration.Settings UseApiEndpointDelegatingHandler() where T : System.Net.Http.DelegatingHandler { } public HealthChecks.UI.Configuration.Settings UseApiEndpointHttpMessageHandler(System.Func apiEndpointHttpHandler) { } public HealthChecks.UI.Configuration.Settings UseWebHooksEndpointDelegatingHandler() where T : System.Net.Http.DelegatingHandler { } public HealthChecks.UI.Configuration.Settings UseWebhookEndpointHttpMessageHandler(System.Func webhookEndpointHttpHandler) { } } } ``` -------------------------------- ### Configure Azure Queue Storage Health Check (Customized) Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/src/HealthChecks.Azure.Storage.Queues/README.md Configures the health checks builder to include a customized Azure Queue Storage health check. This example specifies a QueueName using an options factory. ```csharp void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new QueueServiceClient(new Uri("azure-queue-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureQueueStorage( optionsFactory: sp => new AzureQueueStorageHealthCheckOptions() { QueueName = "demo" }); } ``` -------------------------------- ### Options Configuration Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.UI.Tests/HealthChecks.UI.approved.txt Configures various UI and API-related options for the health checks. ```APIDOC ## Options ### Description Provides configuration settings for the Health Checks UI, including API paths, page titles, and resource paths. ### Fields - **ApiPath** (string) - The base path for the Health Checks API. - **AsideMenuOpened** (bool) - Whether the aside menu should be opened by default. - **PageTitle** (string) - The title displayed on the Health Checks UI page. - **ResourcesPath** (string) - The path for UI resources. - **UIPath** (string) - The base path for the Health Checks UI. - **WebhookPath** (string) - The path for webhook notifications. - **UseRelativeApiPath** (bool) - Indicates if the API path should be relative. - **UseRelativeResourcesPath** (bool) - Indicates if the resources path should be relative. - **UseRelativeWebhookPath** (bool) - Indicates if the webhook path should be relative. ### Methods - **AddCustomStylesheet(string path)**: Adds a custom stylesheet to the UI. Returns the Options object for chaining. ``` -------------------------------- ### Configure AWS SQS Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/test/HealthChecks.Aws.Sqs.Tests/HealthChecks.Aws.Sqs.approved.txt Use this extension method to add an AWS SQS health check to your ASP.NET Core application. Configure queue names, credentials, and region endpoint via the setup action. ```csharp using HealthChecks.Aws.Sqs; using Microsoft.Extensions.DependencyInjection; // ... builder.Services.AddHealthChecks() .AddSqs(setup: sqsOptions => { sqsOptions.Credentials = new Amazon.Runtime.BasicAWSCredentials("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY"); sqsOptions.RegionEndpoint = Amazon.RegionEndpoint.USEast1; sqsOptions.AddQueue("your-queue-name"); }, name: "sqs-queue-health-check", tags: new[] { "aws", "sqs" }); ``` -------------------------------- ### Register NpgsqlDataSource and Health Check Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/src/HealthChecks.NpgSql/README.md Register NpgsqlDataSource as a singleton and add the PostgreSQL health check. This is the recommended approach for performance. ```csharp void Configure(IServiceCollection services) { services.AddNpgsqlDataSource("Host=pg_server;Username=test;Password=test;Database=test"); services.AddHealthChecks().AddNpgSql(); } ``` -------------------------------- ### Configure Kubernetes Discovery Service Namespaces Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/ui-changelog.md Allows customization of namespaces for the Kubernetes Discovery service. This improves compatibility with IPv4/IPv6 addresses and custom annotations. ```csharp setup.SetNamespaces(namespaces); ``` -------------------------------- ### HealthCheck Custom Resource Definition Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/doc/k8s-operator.md Define a HealthCheck custom resource to deploy the health check UI. This example configures the UI to be exposed as a LoadBalancer, sets a custom stylesheet, and applies specific service annotations for Azure. ```yaml apiVersion: "aspnetcore.ui/v1" kind: HealthCheck metadata: name: healthchecks-ui namespace: demo spec: name: healthchecks-ui scope: Namespaced #The UI will be created at specified namespace (demo) and will watch healthchecks services in demo namespace only #scope: Cluster The UI will be created at specified namespace (demo) but will watch healthcheck services across all namespaces servicesLabel: HealthChecks serviceType: LoadBalancer stylesheetContent: > :root { --primaryColor: #2a3950; --secondaryColor: #f4f4f4; --bgMenuActive: #e1b015; --bgButton: #e1b015; --logoImageUrl: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/WoW_icon.svg/1200px-WoW_icon.svg.png'); --bgAside: var(--primaryColor); } serviceAnnotations: - name: service.beta.kubernetes.io/azure-load-balancer-internal value: "true" ``` -------------------------------- ### Configure NATS Health Check with Builder Extension Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/src/HealthChecks.Nats/README.md Use this extension to add a NATS health check to your ASP.NET Core application's service collection. Ensure the NATS.Net package is installed. The NATS server URL is mandatory. ```csharp public void ConfigureServices(IServiceCollection services) { var options = NatsOpts.Default with { Url = "nats://demo.nats.io:4222" }; services .AddSingleton(new NatsConnection(options)) .AddHealthChecks() .AddNats(); } ``` -------------------------------- ### Add HealthChecks UI with MySQL Storage Source: https://github.com/xabaril/aspnetcore.diagnostics.healthchecks/blob/master/README.md Set up HealthChecks UI with MySQL storage by providing the necessary connection string. ```csharp services .AddHealthChecksUI() .AddMySqlStorage("connectionString"); ``` -------------------------------- ### Configure HTTP Client for Health Checks UI Source: https://context7.com/xabaril/aspnetcore.diagnostics.healthchecks/llms.txt Customize HTTP clients and message handlers for the Health Checks UI to manage proxies, authentication, and custom headers when accessing health check endpoints. Includes an example of a custom delegating handler for logging. ```csharp services.AddHealthChecksUI(setup => { setup.AddHealthCheckEndpoint("Secured API", "https://api.example.com/healthz"); // Configure HTTP client for API endpoints setup.ConfigureApiEndpointHttpclient((sp, client) => { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your-token"); client.Timeout = TimeSpan.FromSeconds(30); }); // Configure message handler (e.g., for proxy) setup.UseApiEndpointHttpMessageHandler(sp => { return new HttpClientHandler { Proxy = new WebProxy("http://proxy:8080"), UseProxy = true }; }); // Add delegating handler for logging/retry setup.UseApiEndpointDelegatingHandler(); // Configure webhooks HTTP client setup.ConfigureWebhooksEndpointHttpclient((sp, client) => { client.DefaultRequestHeaders.Add("X-Custom-Header", "value"); }); }) .AddInMemoryStorage(); public class LoggingDelegatingHandler : DelegatingHandler { private readonly ILogger _logger; public LoggingDelegatingHandler(ILogger logger) { _logger = logger; } protected override async Task SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { _logger.LogInformation("Health check request to: {Uri}", request.RequestUri); var response = await base.SendAsync(request, cancellationToken); _logger.LogInformation("Health check response: {StatusCode}", response.StatusCode); return response; } } ```