SuperAPI AI 工具集

health-check

部署与运维

查看项目

更新于 10-16 06:02

技能介绍

Health Check 是一个用于检测 HTTP/HTTPS 端点健康状态与可用性的技能,通过 curl 发起 HTTP 请求,支持 HTTP/1.1 和 HTTP/2。它无需 API 密钥即可使用。

用途 该技能适合以下场景:检查某个 URL 是否在线、测试 API 端点健康状态、监控服务可用性、ping Web 服务、验证 HTTPS 证书、检查响应时间。它不适用于复杂 API 交互(应使用 http-request)、浏览器测试(应使用 browser-tools)、DNS 查询(应使用 dig/nslookup)以及端口扫描(应使用网络工具)。

主要能力

  • 基础健康检查:对单个 URL 发起检查。
  • 批量检查:可一次传入多个 URL,或通过 --file 从文件读取 URL 列表(每行一个)。
  • 超时配置:支持 --timeout(总超时,默认 30 秒)、--connect-timeout(连接超时,默认 5 秒)、--read-timeout(读取超时,默认 10 秒)。
  • 重试:通过 --retries 设置重试次数,默认 0。
  • 响应校验:--expect-status 校验期望的 HTTP 状态码(默认 200,可传多个如 200,201,301);--expect-body 用正则校验响应体;--expect-json 按 JSON 路径校验值。
  • SSL/TLS 选项:--insecure 跳过 SSL 验证;--cert 与 --key 指定客户端证书及其密钥。
  • 输出格式:--format 支持 short(默认)、detailed、json、table。
  • 其他选项:--headers 显示响应头;--follow-redirects 设置最大重定向次数(默认 5);--parallel 并行检查多个 URL。

使用方式 基础检查:{baseDir}/health.sh <url>,例如 {baseDir}/health.sh https://api.example.com/health 或 {baseDir}/health.sh http://localhost:3000。 多端点检查:{baseDir}/health.sh https://api.example.com/health https://api.example.com/status,或 {baseDir}/health.sh --file urls.txt。 超时配置:{baseDir}/health.sh https://api.example.com --timeout 10,或 --connect-timeout 5 --read-timeout 10。 响应校验:--expect-status 200、--expect-status 200,201,301、--expect-body "ok"、--expect-json '{"status":"ok"}'。 SSL/TLS:--insecure,或 --cert /path/to/cert --key /path/to/key。 输出格式:--format json、--format short、--format detailed,或 --file urls.txt --format table。

输出格式说明

  • short(默认):如 ✅ https://api.example.com/health (200, 145ms)。
  • detailed:包含 URL、状态、响应时间、DNS 时间、连接时间、TLS 时间、Content-Type、Content-Length、证书信息等。
  • json:包含 url、status、statusText、responseTime、dnsTime、connectTime、tlsTime、headers、certificate(valid、expiresAt)、healthy 等字段。
  • table:以表格展示 URL、Status、Time、Healthy。

退出码 0:全部检查通过;1:一个或多个检查失败;2:参数无效;3:网络/DNS 错误;4:超时。

限制与说明 该技能使用 curl 发起 HTTP 请求,支持 HTTP/1.1 与 HTTP/2,默认跟随重定向(最多 5 次),默认验证 SSL 证书(可用 --insecure 跳过)。响应时间包含 DNS、连接、TLS 和传输时间。可通过 --parallel 并行检查多个 URL。