Skip to content

Replace vmstat gem with /proc reads - #5332

Open
johha wants to merge 1 commit into
mainfrom
replace-vmstat-with-proc
Open

Replace vmstat gem with /proc reads#5332
johha wants to merge 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

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.
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.

1 participant