Package reference page maintained from the source documentation in src/HealthChecks.Cassandra.
Cassandra Health Check
This health check verifies the ability to communicate with Apache Cassandra. It uses the CassandraCSharpDriver library.
NuGet
dotnet add package DotNetDiag.HealthChecks.Cassandra
Example Usage
With all of the following examples, you can additionally add the following parameters:
options: OptionalCassandraHealthCheckOptionsto set a specific keyspace to connect to.name: The health check name. Default if not specified iscassandra.failureStatus: TheHealthStatusthat should be reported when the health check fails. Default isHealthStatus.Unhealthy.tags: A list of tags that can be used to filter sets of health checks.timeout: ASystem.TimeSpanrepresenting the timeout of the check.
Resolve ICluster from the service provider
void Configure(IHealthChecksBuilder builder)
{
builder.Services
.AddSingleton<ICluster>(sp => Cluster.Builder()
.AddContactPoint("localhost")
.Build())
.AddHealthChecks()
.AddCassandra(sp => sp.GetRequiredService<ICluster>());
}
Connect to a specific keyspace
void Configure(IHealthChecksBuilder builder)
{
builder.Services
.AddHealthChecks()
.AddCassandra(
sp => sp.GetRequiredService<ICluster>(),
options: new CassandraHealthCheckOptions { Keyspace = "mykeyspace" });
}
Use a cluster factory inline
void Configure(IHealthChecksBuilder builder)
{
builder.Services
.AddHealthChecks()
.AddCassandra(
_ => Cluster.Builder().AddContactPoint("localhost").Build(),
name: "cassandra-db",
tags: ["cassandra", "db"]);
}