@cloudnative/health

中文文档
2.1.2发布于 2019/12/05Apache-2.0CommonJS零依赖近 30 天下载 10万

Utility module for building Health Check endpoints

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录5 节
  1. Using Cloud Health
  2. Using Cloud Health with Node.js
  3. Using Cloud Health with Typescript
  4. Module Long Term Support Policy
  5. License

Cloud Health

npm Build status Coverage Status Greenkeeper Module LTS Adopted IBM Support

A core library to provide application lifecycle handling and liveness checks for Node.js applications.

Cloud Health is used by Cloud Health Connect to provide a Connect Middleware for use in Express.js, Loopback and other frameworks that provides:

  • Startup checks
  • Readiness checks
  • Liveness checks
  • Shutdown handling

for use with Kubernetes and Cloud Foundry based clouds.

Using Cloud Health

Cloud Health allows you to register promises which are executed during the three phases of your application, and allows you to call getLivenessStatus(), getReadinessStatus(), or a combined getStatus() to return a promise which resolves to whether the application is STARTING, UP, DOWN, STOPPING or STOPPED.

  1. At startup for "startup"
    Promises that are created as part of a StartupCheck and registered using registerStartupCheck are executed at startup and can be used to execute any code that must complete before your application is ready. If the startup promises are still running, calls to getLivenessStatus(), getReadinessStatus(), and getStatus(), return STARTING. Once the promises complete, DOWN is reported if there were any failures, or the "liveness" and/or "readiness" promises are then executed.

  2. At runtime for "liveness"
    Promises that are created as part of a LivenessCheck and registered using registerLivenessCheck are executed on calls to getLiveness() and getStatus(). These can be used to ensure that the application is still running correctly. If no promises are registered, or the complete successfully, UP is reported. If there are any failures, DOWN is reported.

  3. At runtime for "readiness"
    Promises that are created as part of a ReadinessCheck and registered using registerReadinessCheck are executed on calls to getReadinessStatus() and getStatus(). These can be used to ensure that the application is still running correctly. If no promises are registered, or the complete successfully, UP is reported. If there are any failures, DOWN is reported.

  4. On a SIGTERM signal for shutdown
    Promises that are created as part of a ShutdownCheck and registered using registerShutdownCheck are executed when the process receives a SIGTERM making it possible to clean up any resources used by the application. If the shutdown promises are still running, calls to getReadinessStatus(), getLivenessStatus() and getStatus() return STOPPING. Once the promises complete, STOPPED is reported.

Readiness vs. Liveness

Liveness and readiness checks are executed in the same way but are executed independently (based on calls to getLivenessStatus() or getReadinessStatus()) or together (based on calls to getStatus()).

The difference between liveness and readiness is intended to be purpose: readiness should be used to denote whether an application is "ready" to receive requests, and liveness should be used to denote whether an application is "live" (vs. in a state where it should be restarted).

Using Cloud Health with Node.js

  1. Installation:
npm install @cloudnative/health
  1. Set up a HealthChecker:
const health = require('@cloudnative/health');
let healthcheck = new health.HealthChecker();
  1. Register a startupCheck promise:
const startPromise = () => new Promise(function (resolve, _reject) {
  setTimeout(function () {
    console.log('STARTED!');
    resolve();
  }, 10);
});
let startCheck = new health.StartupCheck("startCheck", startPromise);
healthcheck.registerStartupCheck(startCheck);

Note that registerStartupCheck() also returns a promise which can be used to wait until the promise is resolved.

  1. Register a livenessCheck promise:
const livePromise = () => new Promise(function (resolve, _reject) {
  setTimeout(function () {
    console.log('ALIVE!');
    resolve();
  }, 10);
});
let liveCheck = new health.LivenessCheck("liveCheck", livePromise);
healthcheck.registerLivenessCheck(liveCheck);
  1. Register a shutdownCheck promise:
const shutdownPromise = () => new Promise(function (resolve, _reject) {
  setTimeout(function () {
    console.log('DONE!');
    resolve();
  }, 10);
});
let shutdownCheck = new health.ShutdownCheck("shutdownCheck", shutdownPromise);
healthcheck.registerShutdownCheck(shutdownCheck);
  1. Check the applications status:
healthcheck.getStatus()
.then((result) => console.log('STATUS: ' + JSON.stringify(result)));

Note that Cloud Health Connect provides a Connect Middleware for use in Express.js, Loopback and other frameworks that exposes the results as an endpoint for us in Cloud Foundry and Kubernetes based clouds.

Using Cloud Health with Typescript

The Cloud Health module is created in TypeScript and as such provides out of the box TypeScript support.

Module Long Term Support Policy

This module adopts the Module Long Term Support (LTS) policy, with the following End Of Life (EOL) dates:

Module VersionRelease DateMinimum EOLEOL WithStatus
2.x.xMay 2019April 2021Current
1.x.xJuly 2018Dec 2019LTS

License

Apache-2.0

版本与发布记录

@cloudnative/health 共发布 7 个版本,首次发布于 2018/07/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.2latest2019/12/056 年前
2.1.12019/09/257 年前
2.1.02019/09/207 年前
2.0.02019/05/177 年前
1.0.12018/12/037 年前
1.0.02018/07/248 年前

关于 @cloudnative/health 的常见问题

@cloudnative/health 是什么?

Utility module for building Health Check endpoints注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @cloudnative/health?

在项目目录运行 npm install @cloudnative/health,或使用 pnpm add / yarn add / bun add。

@cloudnative/health 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cloudnative__health 是否存在。

@cloudnative/health 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cloudnative/health 可以商用吗?

@cloudnative/health 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cloudnative/health 的下载量有多少?

根据 npm 官方下载统计,@cloudnative/health 在 2026/10/10 – 2026/11/08 这 30 天内被下载 99,561 次,日均约 3,319 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cloudnative/health 还在维护吗?

最新版本 2.1.2 发布于 2019/12/05(6 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/07/19。作者已将其标记为弃用,新项目建议寻找替代方案。