health-api


License

License

Categories

Categories

Net
GroupId

GroupId

com.netflix.runtime
ArtifactId

ArtifactId

health-api
Last Version

Last Version

1.1.4
Release Date

Release Date

Type

Type

jar
Description

Description

health-api
health-api
Project URL

Project URL

https://github.com/Netflix/runtime-health
Source Code Management

Source Code Management

https://github.com/Netflix/runtime-health.git

Download health-api

How to add to project

<!-- https://jarcasting.com/artifacts/com.netflix.runtime/health-api/ -->
<dependency>
    <groupId>com.netflix.runtime</groupId>
    <artifactId>health-api</artifactId>
    <version>1.1.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.netflix.runtime/health-api/
implementation 'com.netflix.runtime:health-api:1.1.4'
// https://jarcasting.com/artifacts/com.netflix.runtime/health-api/
implementation ("com.netflix.runtime:health-api:1.1.4")
'com.netflix.runtime:health-api:jar:1.1.4'
<dependency org="com.netflix.runtime" name="health-api" rev="1.1.4">
  <artifact name="health-api" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.netflix.runtime', module='health-api', version='1.1.4')
)
libraryDependencies += "com.netflix.runtime" % "health-api" % "1.1.4"
[com.netflix.runtime/health-api "1.1.4"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Health check

Instance health is an important aspect of any cloud ready application. It is used for service discovery as well as bad instance termination. Through HealthCheck API an application can expose a REST endpoint for external monitoring to ping for health status or integrate with Eureka for service discovery registration based on instance health state. An instance can be in one of 2 lifecycle states: Healthy and Unhealthy.

The HealthCheck API is broken up into two abstractions to allow for maximum customization.

  • HealthIndicator - boolean health indicator for a specific application features/aspect. For example, CPU usage.
  • HealthCheckAggregator - combines indicators to derive a meaningful health state. Responsible caching of HealthIndicators, basic error handling and HealthIndicator timeouts. Also enriches Health information with details such as the indicator name and whether or not a Health entry was cached.

Artifacts

Runtime-health is published as the following artifacts:

# api package for libraries
com.netflix.runtime:health-api

# core implementation of runtime-health for applications and services
com.netflix.runtime:health-core

# guice integration with module HealthModule() and netflix archaius2 integration for configuration
com.netflix.runtime:health-guice

# integration with netflix eureka and bridging of health state and eureka status
com.netflix.runtime:health-integrations

Using HealthCheck in a Jersey resource

    @Path("/health")
    public class HealthCheckResource {
        @Inject
        public HealthCheckResource(HealthCheckAggregator healthCheck) {
            this.healthCheck = healthCheck;
        }

        @GET
        public HealthCheckStatus doCheck() {
            return healthCheck.check().get();
        }
    }

Custom health check

To create a custom health indicator simply implement HealthIndicator, inject any objects that are needed to determine the health state, and implement you logic in check(). Note that check returns a future so that the healthcheck system can implement a timeout. The check() implementation is therefore expected to be well behaved and NOT block.

    public class MyHealthIndicator implements HealthIndicator {
        @Inject
        public MyHealthIndicator(MyService service) {
            this.service = service;
        }

        @Override
        public void check(HealthIndicatorCallback healthCallback) {
            if (service.getErrorRate() > 0.1) {
                healthCallback.inform(Health.unhealthy().withDetails("errorRate", service.getErrorRate()));
            }
            else {
                healthCallback.inform(Health.healthy());
            }
        }
    }

To register a HealthIndicator simply provide it when installing HealthModule. It will automatically be picked up by the default HealthCheckAggregator

 InjectorBuilder.fromModules(new HealthModule() {
      protected void configureHealth() {
          bindAdditionalHealthIndicator().to(MyHealthIndicator.class);
          bindAdditionalHealthIndicator().to(AnotherHealthIndicator.class);  //e.g. if you have a second indicator defined
      }
 }).createInjector()

Additional Integrations

See health-integrations for additional integrations (e.g. with eureka)

com.netflix.runtime

Netflix, Inc.

Netflix Open Source Platform

Versions

Version
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1