@absolutejs/卫生
活性+绝对JS基质的准备状态探测器. 一个爱丽西亚 插件, 两个端点, 一个装入平衡器的标准 JSON 信封 和Kubernetes风格的管弦乐手 理解出盒子.
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
两个终点,两个语义
| 终点 | 目的 | 用于 |
|---|---|---|
/healthz | "这个过程还活着吗?" 若为 fail,管弦乐器重新启动容器. | 系统活性探测器 WatchdogSec, (中文(简体) ), @absolutejs/runtime |
/readyz | "这个案例现在能为交通服务吗?" 若为 fail,LB停止通向它(但不会杀死它). | 负载平衡器健康检查、排水流程 |
区别很重要:一个耗尽的实例返回 readyz: fail
healthz: pass. LB在飞行时停止发送新流量 请求结束.
身体形状
{
"status": "pass",
"at": 1717161600000,
"checks": {
"queue": {
"status": "pass",
"latencyMs": 1,
"observed": { "runs": 1057, "failed": 0 }
},
"postgres": { "status": "pass", "latencyMs": 12 }
}
}
与 IETF 健康检查 JSON
草案
编辑 库伯涅斯 livez 编号 :
readyz
公约. content-type: application/health+json。 。 。 .
状态代码
pass→200 OKwarn→200 OK(不要改变交通路线;在仪表板上表面)fail→503 Service Unavailable
LBs路由在状态代码上;人类+仪表板读取身体.
合计
状态是任何检查的 WORST : fail > warn > pass单人
无法依赖整个信封 — 与 Kubernetes 相同
/healthz 卷起行为.
检查工厂
probeCheck(name, () => promise)- 任何包装() => Promise<unknown>. 决定 .pass; 投掷fail与 错误消息.metricsCheck(name, () => metrics(), evaluator)- 读取a 底盘包metrics()决定通过/警告/失败。 抓图 值可登陆observed为仪表板.httpCheck(name, url, options?)—— 说GET url和级别,由HTTP 状态。 2xx – (中文(简体) )pass任何其它东西fail。 。 。 .- 自己滚 - 任何
{ name, check: () => CheckResult | Promise<CheckResult> }工作时.
过滤
{ name: 'shutting-down', kind: 'readiness', check: () => ({
status: draining ? 'fail' : 'pass'
})}
一张支票 kind (单位:千美元)'liveness' 编号 : 'readiness' 编号 : 'both'默认值
'both'控制它运行的终点。 下游运行重
检查只在准备状态下进行; 将现场活动限于“联合来文”
过程是反应"
许可证
BSL-1.1 与主机运行时间/合成时间对应的指定例外 监测服务。 变更日期:2030-05-31 (Apache 2.