elastic / elastic/apm-agent-nodejs

Use Node.js process memory constraint APIs for system memory metrics

Open
#5,106 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**
When the Node.js APM agent runs inside a container with memory limits, host-level memory metrics can be misleading. The agent currently reports memory values based on OS-level totals and availability, which may reflect the host instead of the effective memory limit available to the process.

This makes APM system memory metrics less useful for containerized workloads, because dashboards and alerts can show memory usage relative to a much larger host memory pool rather than the container's configured resource limit.

**Describe the solution you'd like**
Use Node.js process memory constraint APIs directly when they are available:

- `process.constrainedMemory()` for the effective memory limit.
- `process.availableMemory()` for memory available to the process.

If both methods are available and `process.constrainedMemory()` returns a meaningful value, the agent could use those values for memory metrics such as total and available memory. If either API is unavailable, or if no constrained memory value is reported, the agent should keep the current behavior.

**Describe alternatives you've considered**
The main alternative is reading cgroup files directly. Using the Node.js process APIs would be preferable because it lets Node handle platform and cgroup-version differences and avoids duplicating that detection logic in the agent.

**Additional context**
This would improve metric accuracy for containerized Node.js services running with memory limits in environments such as Docker and Kubernetes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.