# @financial-times/health-check 中文文档

规范地址：https://npmcn.com/package/%40financial-times/health-check/

版本：4\.0\.0
npm 元数据更新时间：2026-10-06T13:38:40.012Z
中文译文更新时间：2026-11-14T18:17:04.574Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40financial-times/health-check
原文对照：https://npmcn.com/package/%40financial-times/health-check/?lang=original
项目主页：https://github.com/Financial-Times/node-health-check
源码仓库：https://github.com/Financial-Times/node-health-check

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：134 kB，48 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=18
- 运行依赖：4 个
- 首次发布：2017-04-24T08:57:37.122Z
- 最新版本发布：2024-05-20T15:07:19.393Z
- 近 30 天下载量：6183（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：40（近 12 个月 0 个）

## 中文简介

建立符合FT健康检查标准的体检功能

## 安装

```sh
npm install @financial-times/health-check
```

也可以使用：`pnpm add @financial-times/health-check`、`yarn add @financial-times/health-check`、`bun add @financial-times/health-check`

## README

# 节点健康检查 [![NPM version](https://img.shields.io/npm/v/@financial-times/health-check.svg)](https://www.npmjs.com/package/@financial-times/health-check) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://npmcn.com/package/%40financial-times/health-check/#readme-license)

建立符合下列条件的健康检查功能: [FT健康检查标准](https://docs.google.com/a/ft.com/document/d/18hefJjImF5IFp9WvPAm9Iq5_GmWzI9ahlKSzShpQl1s/edit?usp=sharing)。 。 。 .

## 目录

-   [使用量](https://npmcn.com/package/%40financial-times/health-check/#readme-usage)
    -   [所需资源](https://npmcn.com/package/%40financial-times/health-check/#readme-requirements)
    -   [API 文档](https://npmcn.com/package/%40financial-times/health-check/#readme-api-documentation)
    -   [选项](https://npmcn.com/package/%40financial-times/health-check/#readme-options)
    -   [健康检查配置](https://npmcn.com/package/%40financial-times/health-check/#readme-health-check-configurations)
    -   [实例](https://npmcn.com/package/%40financial-times/health-check/#readme-examples)
    -   [节点获取](https://npmcn.com/package/%40financial-times/health-check/#readme-node-fetch)
-   [捐款](https://npmcn.com/package/%40financial-times/health-check/#readme-contributing)
-   [出版](https://npmcn.com/package/%40financial-times/health-check/#readme-publishing)
-   [移徙指南](https://npmcn.com/package/%40financial-times/health-check/#readme-migration-guide)
-   [联系人](https://npmcn.com/package/%40financial-times/health-check/#readme-contact)
-   [许可证](https://npmcn.com/package/%40financial-times/health-check/#readme-licence)

## 使用量

### 所需资源

运行健康检查模块需要 [节点.js](https://nodejs.org/) 财务报告和审定财务报表 [无](https://www.npmjs.com/)。您可以安装 :

```sh
npm install @financial-times/health-check
```

### API 文档

这个图书馆利用 [承诺](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) - API的其他文件假定熟悉。 您还需要使用以下模块:

```js
const HealthCheck = require('@financial-times/health-check');
```

### `new HealthCheck( [options] )`

此函数返回一个新的健康检查对象 。 您可以配置健康检查 [选项对象](https://npmcn.com/package/%40financial-times/health-check/#readme-options) 如果您需要覆盖任何默认值.

```js
const health = new HealthCheck({
    checks: [
        // ...
    ]
});
```

这个 [给定检查](https://npmcn.com/package/%40financial-times/health-check/#readme-health-check-configurations) 在您指定的间隔时间立即开始投票。 返回实例有几种读取此数据的方法.

#### `health.checks()`

返回一个符合 [快速网络服务](https://github.com/Financial-Times/express-web-service) 模块。 返回的函数返回一个承诺,该承诺将解决健康检查数据JSON的方便副本.

假设你已经包括 [快递](https://expressjs.com/) 财务报告和审定财务报表 [快速网络服务](https://github.com/Financial-Times/express-web-service)数字 :

```js
app.use(expressWebService({
    healthCheck: health.checks()
}));
```

#### `health.gtg()`

返回一个与 [快速网络服务](https://github.com/Financial-Times/express-web-service) 模块。 返回的函数返回一个承诺 `true` 或者说 `false`。 。 。 .

`false` 如果任何健康检查具有严重性,则确定值 `1` 正在失败.

假设你已经包括 [快递](https://expressjs.com/) 财务报告和审定财务报表 [快速网络服务](https://github.com/Financial-Times/express-web-service)数字 :

```js
app.use(expressWebService({
    goodToGoTest: health.gtg()
}));
```

#### `health.toJSON()`

将健康检查输出作为可以转换为JSON的阵列. 如果你不打算使用这个 [快速网络服务](https://github.com/Financial-Times/express-web-service) 模块.

#### `health.stop()`

这阻止了所有的支票运行。 如果健康检查能打开节点Js的过程 并且你需要关闭它的话,这是有用的。 例如,综合测试后.

```js
health.stop();
```

### `new HealthCheck.Check( [options] )`

此类用于创建自定义的健康检查. 需要扩展这个课程才能使用,并且可以直接通过实例进入 `HealthCheck` 当你立即把它。 举个例子.

```js
class MyHealthCheck extends HealthCheck.Check {

    constructor(options) {
        super(options);
    }

    // Must return a promise
    run() {
        return new Promise(resolve => {
            // Must set these properties
            this.ok = true;
            this.checkOutput = '';
            this.lastUpdated = new Date();
            resolve();
        });
    }

}
```

[参见示例](https://npmcn.com/package/%40financial-times/health-check/#readme-examples) 获取更多信息,或查看 [`lib/check`](https://npmcn.com/package/%40financial-times/health-check/lib/check) 更多已经扩展基数的类别.

### 选项

健康检查模块可配置各种选项,作为对象传递到 `HealthCheck` 建筑师。 现有备选方案如下:

-   `checks`: 数组 [健康检查配置对象](https://npmcn.com/package/%40financial-times/health-check/#readme-health-check-configurations)默认为空数组
-   `log`: 用于输出日志的控制台对象。 全局默认值 `console` 对象

### 健康检查配置

每次健康检查都可以被配置为对象. 这些跟随 [FT健康检查标准](https://docs.google.com/a/ft.com/document/d/18hefJjImF5IFp9WvPAm9Iq5_GmWzI9ahlKSzShpQl1s/edit?usp=sharing),它有更多的信息, 并且有 [实例](https://npmcn.com/package/%40financial-times/health-check/#readme-examples) 可以帮助你。 无论您添加何种类型的检查, 都有一些常见的属性:

-   `type`: 支票的类型. 一个 `cpu`, (中文(简体) ), `disk-space`, (中文(简体) ), `memory`, (中文(简体) ), `ping-url`, (中文(简体) ), `tcp-ip`这些类型所需的额外配置记录如下:
-   `businessImpact`: 健康检查作为字符串的商业影响
-   `id`:健康检查作为字符串的独特ID. 必须只使用小写字母和连字符 .
-   `name`:健康检查的名称为字符串.
-   `panicGuide`: 健康检查的恐慌指南为一串.
-   `technicalSummary`:健康检查技术摘要为一串.

还有一些共同的可选属性:

-   `severity`: 如果健康检查失败,其严重程度如何。 一定是其中一个 `1` (高点), `2` (中间), `3` (减)
-   `interval`: 检查之间等待的毫秒数。 默认为 `30000` (30秒)

不同类型的检查可能具有额外的配置属性. 现将这些情况记录如下.

#### 检查类型: CPU

这个 `cpu` 类型接受一些额外的配置 :

-   `threshold`: 检查前允许的最大 CPU 使用量( 百分比) 。 默认为 `50`

#### 检查类型: 磁盘空格

这个 `disk-space` 类型接受一些额外的配置 :

-   `threshold`:在检查失败前允许的最大磁盘空间使用(百分比). 默认为 `75`

#### 检查类型: 内存

这个 `memory` 类型接受一些额外的配置 :

-   `threshold`:在检查失败前允许的最大内存使用量(百分比). 默认为 `75`

#### 检查类型: Ping URL

这个 `ping-url` 类型需要一些额外的配置 :

-   `url`: 检查时应该打的URL. 此接受一个字符串或返回字符串的函数
-   `method`: Ping URL时使用的HTTP方法. 默认为 `"HEAD"`
-   `headers`: HTTP 信头随请求而发送. 此接受带有密钥值对的对象 。 默认为空对象

#### 检查类型: TCP/IP

这个 `tcp-ip` 类型需要一些额外的配置 :

-   `host`: 检查时要键入的主机名
-   `port`: 键入主机名时使用的TCP端口. 默认为 `80`

见 `examples` 用于样本使用.

### 实例

健康检查的落实情况 `examples` 此 repo 文件夹 :

-   **基础 :** 创建并运行一些简单的健康检查:
    
    ```sh
    node examples/basic
    ```
    
    [源文件](https://github.com/Financial-Times/node-health-check/blob/master/example/basic/index.js)
    
-   **自定义 :** 创建和运行一些定制的健康检查 :
    
    ```sh
    node examples/custom
    ```
    
    [源文件](https://github.com/Financial-Times/node-health-check/blob/master/example/custom/index.js)
    

### 节点获取

如果项目正在使用 `node-fetch` 作为npm的依赖者,有一个潜在的 需要意识到,因为没有 `response` 对于身体的定制健康检查,它将引入内存漏出,随着时间的推移会逐渐积聚起来,并因没有软件而崩溃应用程序 `response` 已经就位.

需要围绕这个问题开展工作。 要么放进.. `response.json` 或一个 `response.text` 在海关健康检查中,如下:

```js
const fetch = require('node-fetch');

class MyHealthCheck extends HealthCheck.Check {
    async run() {
        try {
            const response = await fetch('https://some.api-address.com', {
                method: 'GET',
                headers: {
                    'apikey': 'your api key here'
                }
            });

            if (response.status !== 200) {
                throw new Error('Unable to access API');
            }

            if (response.status === 200) {
                this.ok = true;
                this.checkOutput = 'OK';
                response.text(); // read the body so it can be garbage collected
            }

        } catch (error) {
            this.ok = false;
            this.checkOutput = error.toString();
        }
    }
}
```

## 捐款

这个模块有一套完整的单元测试,通过ESLint验证. 您可以在打开拉出请求前使用下列命令来检查您的代码 .

```sh
make verify  # verify JavaScript code with ESLint
make test    # run the unit tests and check coverage
```

## 出版

当创建匹配模式的新标记时, CI 将自动发布模块的新版本 `/v.*/`。 。 。 .

## 移徙指南

| 状态 | 主要版本 | 最后一个小版本 | 移徙指南 |
| :-: | :-: | :-: | :-: |
| 活动 | 页:1 | 不详 | [迁移到 v4](https://npmcn.com/package/%40financial-times/health-check/MIGRATION.md#migrating-from-v3-to-v4) |
| 已贬值 | 3个 | 不详 | [迁移到 v3](https://npmcn.com/package/%40financial-times/health-check/MIGRATION.md#migrating-from-v2-to-v3) |
| 已贬值 | 2.1 国家 | 不详 | [迁移到 v2](https://npmcn.com/package/%40financial-times/health-check/MIGRATION.md#migrating-from-v1-to-v2) |
| 已贬值 | 1个 | 1.11 联合国 | 不详 |

## 联系人

如果您对本单元有任何问题或评论,或需要帮助使用,请 [提出问题](https://github.com/Financial-Times/node-health-check/issues)访问 [#origami - 支持](https://financialtimes.slack.com/messages/origami-support/) 或电子邮件 [折纸支持](mailto:origami-support@ft.com)。 。 。 .

## 许可证

本软件由金融时报根据以下规定出版: [麻省理工学院许可证](http://opensource.org/licenses/MIT)。 。 。 .

## 常见问题

### @financial-times/health-check 是什么？

建立符合FT健康检查标准的体检功能

### 如何安装 @financial-times/health-check？

在项目目录运行 npm install @financial-times/health-check，或使用 pnpm add / yarn add / bun add。

### @financial-times/health-check 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/financial-times\_\_health-check 是否存在。

### @financial-times/health-check 支持 ESM 还是 CommonJS？

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

### @financial-times/health-check 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @financial-times/health-check 可以商用吗？

@financial-times/health-check 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @financial-times/health-check 的下载量有多少？

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

### @financial-times/health-check 还在维护吗？

最新版本 4\.0\.0 发布于 2024/05/20（2 年前）；至今共发布 40 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/04/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

