HealthIndicator<T extends Object> class
abstract
Base class for health indicators that check service dependencies.
Health indicators are used by the health check system to determine whether the server is ready to handle requests. Each indicator checks a specific dependency (database, Redis, external service, etc.).
The type parameter T specifies the type of observedValue that this
indicator produces, providing type safety when creating results.
Example implementation:
class MyServiceHealthIndicator extends HealthIndicator<double> {
@override
String get name => 'myservice:connection';
@override
String get componentType => HealthComponentType.component.name;
@override
String get observedUnit => 'ms';
@override
Future<HealthCheckResult> check() async {
final stopwatch = Stopwatch()..start();
try {
await myService.ping();
stopwatch.stop();
return pass(observedValue: stopwatch.elapsedMilliseconds.toDouble());
} catch (e) {
return fail(output: 'Connection failed: $e');
}
}
}
Constructors
- HealthIndicator()
-
Const ctor to allow subclasses the same
const
Properties
- componentId → String?
-
Unique identifier for the component instance.
no setter
- componentType → String?
-
Type of the component.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Human-readable name for this indicator.
no setter
- observedUnit → String?
-
Unit of the observed value, e.g.,
ms,percent,bytes.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeout → Duration
-
Maximum time to wait for this check before considering it failed.
no setter
Methods
-
check(
) → Future< HealthCheckResult> - Perform the health check and return the result.
-
fail(
{T? observedValue, String? output, DateTime? time}) → HealthCheckResult - Creates a failing health check result for this indicator.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pass(
{T? observedValue, String? output, DateTime? time}) → HealthCheckResult - Creates a passing health check result for this indicator.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited