Skip to content

Replace vmstat gem with /proc reads - #5332

Merged
johha merged 1 commit into
mainfrom
replace-vmstat-with-proc
Aug 3, 2026
Merged

Replace vmstat gem with /proc reads#5332
johha merged 1 commit into
mainfrom
replace-vmstat-with-proc

Conversation

@johha

@johha johha commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

The vmstat gem is a native C extension with no Windows support (its build fails there), and it surfaced in an outdated-dependency audit. On the Linux ccng runtime all three values it provided are available directly from /proc, so the gem can be dropped from lib/vcap/stats.rb.

Behaviour is preserved. vmstat's Linux backend reads /proc/meminfo, so:

  • memory_free_bytes = (Inactive + MemFree) * 1024
  • memory_used_bytes = (MemTotal - Inactive - MemFree) * 1024 (equals vmstat's active+wired by conservation - the buckets sum to MemTotal)
  • cpu_load_average = first field of /proc/loadavg

Verified against the live vmstat gem on a production CF API VM: 0.0% diff on both memory metrics, load average identical to rounding. Non-Linux dev machines (Mac/Windows) return 0, where these metrics have no consumer.

Add a stats spec covering all three methods on both the Linux and non-Linux paths, which previously had no direct coverage.

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

Comment thread lib/vcap/stats.rb Outdated
The vmstat gem is a native C extension with no Windows support (its build
fails there), and it surfaced in an outdated-dependency audit. On the Linux
ccng runtime all three values it provided are available directly from /proc,
so the gem can be dropped from lib/vcap/stats.rb.

Behaviour is preserved. vmstat's Linux backend reads /proc/meminfo, so:
- memory_free_bytes = (Inactive + MemFree) * 1024
- memory_used_bytes = (MemTotal - Inactive - MemFree) * 1024
  (equals vmstat's active+wired by conservation - the buckets sum to MemTotal)
- cpu_load_average  = first field of /proc/loadavg

Verified against the live vmstat gem on a production CF API VM: 0.0% diff on
both memory metrics, load average identical to rounding. Non-Linux dev
machines (Mac/Windows) return 0, where these metrics have no consumer.

Add a stats spec covering all three methods on both the Linux and non-Linux
paths, which previously had no direct coverage.
@johha
johha force-pushed the replace-vmstat-with-proc branch from 6349061 to 3d94f41 Compare August 3, 2026 09:43
@johha
johha requested a review from kathap August 3, 2026 09:44
@johha
johha merged commit 06a687b into main Aug 3, 2026
11 checks passed
@johha
johha deleted the replace-vmstat-with-proc branch August 3, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants