@absolutejs/health

中文文档
0.5.0发布于 2026/10/24BSL-1.1TypeScriptES Module构建来源已验证近 30 天下载 2043

Liveness + readiness probes for the AbsoluteJS substrate. createHealthChecker composes named checks; healthPlugin exposes /healthz (process alive?) + /readyz (can serve traffic?) with a standard JSON envelope. Per-check timeout, aggregate worst-of-any sta

原始使用文档
文档目录7 节
  1. Two endpoints, two semantics
  2. Body shape
  3. Status codes
  4. Aggregation
  5. Check factories
  6. Kind filtering
  7. License

@absolutejs/health

Liveness + readiness probes for the AbsoluteJS substrate. One Elysia plugin, two endpoints, a standard JSON envelope that load balancers and Kubernetes-style orchestrators understand out of the box.

import { Elysia } from 'elysia';
import {
  createHealthChecker,
  healthPlugin,
  metricsCheck,
  probeCheck,
  httpCheck,
} from '@absolutejs/health';

const checker = createHealthChecker({
  checks: [
    // Synthesis from a substrate package's metrics() snapshot.
    metricsCheck('queue', () => worker.metrics(), (m) => ({
      status: m.failed > 100 ? 'warn' : 'pass',
      observed: { runs: m.runs, failed: m.failed },
    })),

    // Wrap an arbitrary probe.
    probeCheck('postgres', () => pg.query('SELECT 1')),

    // Downstream HTTP dependency.
    httpCheck('otlp-collector', 'http://collector:4318/healthz', {
      kind: 'readiness',  // run only under /readyz
    }),
  ],
});

const app = new Elysia().use(await healthPlugin({ checker }));
// GET /healthz → liveness:  200 / 503 with { status, checks, at }
// GET /readyz  → readiness: same shape, filtered to readiness + both

Two endpoints, two semantics

EndpointPurposeUsed by
/healthz"Is this process alive?" If fail, the orchestrator restarts the container.Kubernetes liveness probe, systemd WatchdogSec, @absolutejs/runtime
/readyz"Can this instance serve traffic right now?" If fail, the LB stops routing to it (but doesn't kill it).Load balancer health checks, drain workflows

The distinction matters: a draining instance returns readyz: fail

  • healthz: pass. The LB stops sending new traffic while in-flight requests finish.

Body shape

{
  "status": "pass",
  "at": 1717161600000,
  "checks": {
    "queue": {
      "status": "pass",
      "latencyMs": 1,
      "observed": { "runs": 1057, "failed": 0 }
    },
    "postgres": { "status": "pass", "latencyMs": 12 }
  }
}

Compatible with the IETF health-check JSON draft and the Kubernetes livez / readyz conventions. content-type: application/health+json.

Status codes

  • pass → 200 OK
  • warn → 200 OK (don't reroute traffic; surface in your dashboard)
  • fail → 503 Service Unavailable

LBs route on status code; humans + dashboards read the body.

Aggregation

Status is the WORST of any check: fail > warn > pass. A single failing dependency fails the whole envelope — same as Kubernetes /healthz rollup behavior.

Check factories

  • probeCheck(name, () => promise) — wrap any () => Promise<unknown>. Resolves → pass; throws → fail with the error message.
  • metricsCheck(name, () => metrics(), evaluator) — read a substrate package's metrics() and decide pass/warn/fail. Snapshot values can land in observed for dashboards.
  • httpCheck(name, url, options?) — GET url and grade by HTTP status. 2xx → pass, anything else → fail.
  • Roll your own — any { name, check: () => CheckResult | Promise<CheckResult> } works.

Kind filtering

{ name: 'shutting-down', kind: 'readiness', check: () => ({
  status: draining ? 'fail' : 'pass'
})}

A check's kind ('liveness' / 'readiness' / 'both', default 'both') controls which endpoint runs it. Run heavy downstream checks under readiness only; keep liveness limited to "the JS process is responsive."

License

BSL-1.1 with named carveout against hosted uptime / synthetic- monitoring services. Change date: 2030-05-31 (Apache 2.0).

版本与发布记录

@absolutejs/health 共发布 7 个版本,首次发布于 2026/05/31;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.0latest2026/10/2415 天前
0.4.02026/08/202 个月前
0.3.02026/07/273 个月前
0.2.12026/07/253 个月前
0.2.02026/07/233 个月前
0.1.12026/07/143 个月前

关于 @absolutejs/health 的常见问题

@absolutejs/health 是什么?

Liveness + readiness probes for the AbsoluteJS substrate. createHealthChecker composes named checks; healthPlugin exposes /healthz (process alive?) + /readyz (can serve traffic?) with a standard JSON envelope. Per-check timeout, aggregate worst-of-any sta

如何安装 @absolutejs/health?

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

@absolutejs/health 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@absolutejs/health 支持 ESM 还是 CommonJS?

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

@absolutejs/health 可以商用吗?

@absolutejs/health 使用 BSL-1.1 许可。声明的许可为 BSL-1.1,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

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

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

@absolutejs/health 还在维护吗?

最新版本 0.5.0 发布于 2026/10/24(15 天前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/05/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。