v1.31.0
conocimientoresilience-patternspatterns/

health-checks.md

Referencia que resilience-patterns carga bajo demanda desde su SKILL.md.

resilience-patternsskill
patternscarpeta
4128 Btamaño
2026-09-21último cambio del pack

Todo proyecto en produccion debe tener health checks configurados.


Paquetes NuGet

<ItemGroup>
  <PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.*" />
  <PackageReference Include="AspNetCore.HealthChecks.Redis" Version="8.*" />
  <PackageReference Include="AspNetCore.HealthChecks.UI" Version="8.*" />
  <PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.*" />
  <PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="8.*" />
</ItemGroup>

Endpoints

EndpointPropositoChecksUso
/healthEstado generalTodosDashboards
/health/readyReadinessDB, Redis, StorageK8s readinessProbe
/health/liveLivenessSelf checkK8s livenessProbe

Checks Obligatorios

SQL Server

services.AddHealthChecks()
    .AddSqlServer(
        connectionString: configuration.GetConnectionString("DefaultConnection")!,
        name: "sqlserver",
        failureStatus: HealthStatus.Unhealthy,
        tags: new[] { "ready", "db" });

Self Check

services.AddHealthChecks()
    .AddCheck("self", () => HealthCheckResult.Healthy("OK"),
        tags: new[] { "live" });

Checks Opcionales

Redis

.AddRedis(configuration.GetConnectionString("Redis")!,
    name: "redis", failureStatus: HealthStatus.Degraded,
    tags: new[] { "ready", "cache" })

Azure Blob Storage

.AddAzureBlobStorage(configuration["AzureStorage:ConnectionString"]!,
    name: "azure-blob", failureStatus: HealthStatus.Degraded,
    tags: new[] { "ready", "storage" })

Custom Health Check

public class CriticalTableHealthCheck : IHealthCheck
{
    private readonly ApplicationDbContext _context;

    public CriticalTableHealthCheck(ApplicationDbContext context)
        => _context = context;

    public async Task<HealthCheckResult> CheckHealthAsync(
        HealthCheckContext context, CancellationToken ct = default)
    {
        try
        {
            var count = await _context.Configuraciones.CountAsync(ct);
            return count == 0
                ? HealthCheckResult.Degraded("Tabla vacia")
                : HealthCheckResult.Healthy($"OK - {count} registros");
        }
        catch (Exception ex)
        {
            return HealthCheckResult.Unhealthy("Error accediendo tabla critica", ex);
        }
    }
}

Configuracion en Program.cs

builder.Services.AddHealthChecks()
    .AddSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")!,
        name: "sqlserver", failureStatus: HealthStatus.Unhealthy,
        tags: new[] { "ready", "db" })
    .AddCheck("self", () => HealthCheckResult.Healthy("OK"),
        tags: new[] { "live" });

app.MapHealthChecks("/health", new HealthCheckOptions
{ ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse });

app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
    Predicate = check => check.Tags.Contains("ready"),
    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});

app.MapHealthChecks("/health/live", new HealthCheckOptions
{
    Predicate = check => check.Tags.Contains("live"),
    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});

Respuesta JSON

{
  "status": "Healthy",
  "totalDuration": "00:00:00.123",
  "entries": {
    "sqlserver": { "status": "Healthy", "tags": ["ready", "db"] },
    "self": { "status": "Healthy", "description": "OK", "tags": ["live"] }
  }
}
EstadoHTTP
Healthy200
Degraded200
Unhealthy503

Kubernetes / Docker

livenessProbe:
  httpGet: { path: /health/live, port: 8080 }
  initialDelaySeconds: 10
  periodSeconds: 15
readinessProbe:
  httpGet: { path: /health/ready, port: 8080 }
  initialDelaySeconds: 5
  periodSeconds: 10

Seguridad

Health endpoints NO deben exponer info sensible en produccion.


Skill resilience-patterns - Health Checks

← Volver a la ficha de resilience-patterns

Ovillo v1.31.0tag v1.31.0 (2026-10-06) · sin decisiones posteriores69 skills · 19 agents · 22 hooks · 3 reglas · 15 tools · 103 decisionesfuente: ovillo/.claude/skills/resilience-patterns/patterns/health-checks.mdCopyright 2026 Hugo Valer Rojas · Apache-2.0