# @adobe/helix-status 中文文档

规范地址：https://npmcn.com/package/%40adobe/helix-status/

版本：10\.1\.5
npm 元数据更新时间：2026-10-01T01:34:25.666Z
中文译文更新时间：2026-11-06T03:12:55.916Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40adobe/helix-status
原文对照：https://npmcn.com/package/%40adobe/helix-status/?lang=original
项目主页：https://github.com/adobe/helix-status#readme
源码仓库：https://github.com/adobe/helix-status

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

- 包体积（解压后）：77.5 kB，8 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：1 个
- 首次发布：2019-08-15T18:31:28.295Z
- 最新版本发布：2024-12-07T15:18:01.226Z
- 近 30 天下载量：5878（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：95（近 12 个月 0 个）

## 中文简介

OpenWhisk 微服务报告状态, 以 Pingdom 或新遗迹检查时速

## 安装

```sh
npm install @adobe/helix-status
```

也可以使用：`pnpm add @adobe/helix-status`、`yarn add @adobe/helix-status`、`bun add @adobe/helix-status`

## README

# 螺旋状态

> 新遗物(及其他)的 OpenWhisk 微服务报告状态( HTTP) 检查

## 状态

[![codecov](https://img.shields.io/codecov/c/github/adobe/helix-status.svg)](https://codecov.io/gh/adobe/helix-status) [![CircleCI](https://img.shields.io/circleci/project/github/adobe/helix-status.svg)](https://circleci.com/gh/adobe/helix-status) [![GitHub license](https://img.shields.io/github/license/adobe/helix-status.svg)](https://github.com/adobe/helix-status/blob/main/LICENSE.txt) [![GitHub issues](https://img.shields.io/github/issues/adobe/helix-status.svg)](https://github.com/adobe/helix-status/issues) [![LGTM Code Quality Grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/adobe/helix-status.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/adobe/helix-status) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

## 问题

您拥有一个作为 OpenWhisk HTTP 动作的微服务, 甚至包括其中的一些 micro services and you want to 建立使用"新遗物"的服务正常时间监控.

万一服务中断,你需要快速了解 是否有问题

-   openWhisk 运行时间, 可能无法到达或超载
-   您的后端 API 提供者之一可能无法访问
-   您自己的服务可能中断(例如由于部署变化)

终于,你知道,有 [新遗迹合成器](https://docs.newrelic.com/docs/synthetics) 不过你 不想在您每个微服务中重复相同的代码返回状态检查 .

## 解决方案

`helix-status` 是一个允许您将自己的动作包成一个标准化的监控响应的库

## 安装

```bash
$ npm install -S @adobe/helix-status
```

## 使用量

在您动作的切入点中,添加

```javascript
const { helixStatus } = require('@adobe/helix-status');
```

到您的文件顶部并覆盖 `module.exports.main` 改为:

```javascript
module.exports.main = helixStatus(main);
```

全体 `GET /_status_check/healthcheck.json` 向您服务的请求现在将以类似于以下的 XML 回复 :

```json
{
  "status": "OK",
  "version": "1.5.4",
  "response_time": 6,
  "process": {}
}
```

您也可以通过将第二个参数传递到 `wrap`数字 :

```javascript
module.exports.main = helixStatus(main, { example: 'http://www.example.com'})
```

你将看见这样的结果:

```json
{
  "status": "OK",
  "version": "1.5.4",
  "response_time": 249,
  "process": {
    "activation": "7ef3047190924313b3047190923313e9"
  },
  "example": 247
}
```

使用代表 API 端点的 URL 是一个好主意, 您的服务在正常操作中调用为检查 .

## 与 Probot 用法

使用时 [高级程序](https://probot.github.io/) 例如通过 [OpenWhisk 上的无服务器Probot](https://github.com/adobe/probot-serverless-openwhisk),其用法略有不同:

```javascript
// import the probot status app
const { probotStatus } = require('@adobe/helix-status');

probot
  .withApp(yourApp)
  .withApp(probotStatus()) //add a status check app 
```

`probotStatus()` 接受相同的建议 `checks` 对象,可以通过一系列URL检查.

# 用新遗物合成器

[新遗迹合成器](https://docs.newrelic.com/docs/synthetics) 是一种类似于平陵的服务。 它可以用来 `helix-status` 通过创建这样的 API 检查脚本 :

```javascript
const assert = require('assert');

// replace the URL with your check URL
$http.get('https://adobeioruntime.net/api/v1/web/helix/helix-services/status@v3/_status_check/heathcheck.json',
  // Callback
  function (err, response, body) {
    assert.equal(response.statusCode, 200, 'Expected a 200 OK response');
    const health = JSON.parse(body);
    assert.equal(health.status, 'OK', 'Expected an OK health check status');
    for (const v in health) {
      if (['status', 'process', 'version'].indexOf(v)===-1) {
        $util.insights.set(v, parseInt(health[v]));
      }
    }
    for (const h in ['x-openwhisk-activation-id', 'x-request-id', 'x-version']) {
      $util.insights.set(h, response.headers[h]);
    }
  }
);
```

# 高级检查

默认, `helix-status` 将绘制 URL 地图并制作 `GET` 请求提供每个URL。 在某些情况下,你需要提供更多的细节来拟订请求和 `helix-status` 支持三种类型的高级检查:

## 请求选项

如果您需要像请求方法( 从 `GET` 改为 `POST`)或设置请求头(例如. `Accept`),而不是作为字符串提供URL,而是可以提供 [根据 `request/request` 文档](https://github.com/request/request#requestoptions-callback)。 。 。 .

千万别忘了 `uri`。 。 。 .

```javascript
module.exports.main = wrap(main, 
  { example: {
    uri: 'http://www.example.com',
    method: 'POST',
    headers: {
      accept: 'application/json'
    }
  }});
```

## 自定义状态检查函数

对于更先进的使用案例,您可以提供 `function` 在你的支票中。 此函数将与 `params` 的功能.

注意检查功能应合理快地执行,但可以同化.

```javascript
module.exports.main = wrap(main, 
  { example: function(params) => params.foo === params.bar });
```

## 请求具有动态值的选项

以上两种技术的结合是使用带有动态值的请求选项. 如果您需要将请求对象或请求信头的属性填入其中提供的值,则可以使用此选项 `params` 处决.

一个典型的例子是向需要API密钥的API发出呼叫,API密钥将存储在OpenWhisk动作的默认参数中.

要做到这一点,请提供以下描述的请求选项对象: [请求选项](https://npmcn.com/package/%40adobe/helix-status/#readme-request-options)中,但请注意 `options` 编辑 `options.headers` 对象可以是 `function`s. 函数的每个属性将被函数在使用动作参数调用时返回的值所取代.

```javascript
module.exports.main = wrap(main, 
  { example: {
    uri: 'http://www.example.com',
    method: 'POST',
    headers: {
      accept: 'application/json',
      authorization: params => `Bearer ${params.EXAMPLE_API_TOKEN}`
    }
  }});
```

上面的例子说明如何提取 `EXAMPLE_API_TOKEN` 从动作的(默认)参数中的值并将其应用到 `Authorization` 头曰.

# 状态代码

健康检查报告遵循HTTP状态代码:

-   `200` (OK):所有健康检查都顺利进行
-   `504` (盖特威超时):健康检查花费了太长的时间来执行
-   `502` (Gateway 错误):健康检查从已检查的 URL 得到错误反应
-   `500` (Server 错误): 通用检查函数未成功执行

# 发展

## 部署螺旋状态

部署螺旋状态要求 `wsk` 命令行客户端,认证为您选择的命名空间。 对于螺旋项目,我们使用 `helix` 名称空间.

所有承诺主机通过测试将自动部署。 所有承诺的分支 通过测试会得到的承诺 `/helix-services/status@ci<num>` 并贴上CI建筑编号.

## 常见问题

### @adobe/helix-status 是什么？

OpenWhisk 微服务报告状态, 以 Pingdom 或新遗迹检查时速

### 如何安装 @adobe/helix-status？

在项目目录运行 npm install @adobe/helix-status，或使用 pnpm add / yarn add / bun add。

### @adobe/helix-status 支持 TypeScript 吗？

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

### @adobe/helix-status 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @adobe/helix-status 可以商用吗？

@adobe/helix-status 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @adobe/helix-status 的下载量有多少？

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

### @adobe/helix-status 还在维护吗？

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

