Skip to content

feat(healthcheck): make memory check cgroup-aware with host fallback#1

Merged
MM25Zamanian merged 1 commit intomainfrom
codex/make-memoryhealthcheck-container-aware
Feb 23, 2026
Merged

feat(healthcheck): make memory check cgroup-aware with host fallback#1
MM25Zamanian merged 1 commit intomainfrom
codex/make-memoryhealthcheck-container-aware

Conversation

@MM25Zamanian
Copy link
Copy Markdown
Member

Motivation

  • Make the memory health check container-aware by reading cgroup limits/usage so reported totals reflect container limits when running in Docker/K8s.
  • Prefer cgroup v2 (/sys/fs/cgroup/memory.max + /sys/fs/cgroup/memory.current) and fall back to cgroup v1 or host metrics when limits are unlimited or unavailable.

Description

  • Added cgroup-aware logic in packages/healthcheck/src/checks/memory.ts that reads v2 files and two common v1 path variants and returns a MemorySnapshot when a finite container limit is detected.
  • Treat memory.max === "max" (v2) and very large v1 limits (heuristic 2 ** 60) as unlimited and fall back to host metrics from systeminformation.mem() while keeping the existing free-ratio threshold checks unchanged.
  • Added metrics.source ("cgroup" | "host") and preserved the existing API surface and free/degraded/unhealthy logic; all cgroup reads are guarded to avoid crashes when files are missing.
  • Added a lightweight verification script packages/healthcheck/scripts/print-memory-source.mjs and a memory:inspect script entry in packages/healthcheck/package.json to print computed source and values.

Testing

  • Ran pnpm --filter @nexload-sdk/healthcheck build which completed successfully.
  • Ran pnpm --filter @nexload-sdk/healthcheck memory:inspect which executed the new script and printed the computed metrics.source and memory values successfully in this environment.
  • Ran pnpm --filter @nexload-sdk/healthcheck lint which failed in this environment due to a workspace @nexload-sdk/eslint-config export issue (ERR_PACKAGE_PATH_NOT_EXPORTED), not related to the changes in the healthcheck logic.

Codex Task

@MM25Zamanian MM25Zamanian merged commit 4680203 into main Feb 23, 2026
@MM25Zamanian MM25Zamanian deleted the codex/make-memoryhealthcheck-container-aware branch February 23, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant