Skip to content

Commit 9b7988a

Browse files
Consistent use of _size suffix.
1 parent 80f6a39 commit 9b7988a

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

lib/process/metrics/host/memory.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ module Metrics
88
# Per-host (system-wide) memory metrics. Use Host::Memory for total/used/free and swap; use Process::Metrics::Memory for per-process metrics.
99
module Host
1010
# Struct for host memory snapshot. All sizes in bytes.
11-
# @attribute total [Integer] Total memory (cgroup limit when in a container, else physical RAM).
12-
# @attribute used [Integer] Memory in use (total - free).
13-
# @attribute free [Integer] Available memory (MemAvailable-style: free + reclaimable).
14-
# @attribute swap_total [Integer, nil] Total swap, or nil if not available.
15-
# @attribute swap_used [Integer, nil] Swap in use, or nil if not available.
16-
Memory = Struct.new(:total, :used, :free, :swap_total, :swap_used) do
11+
# @attribute total_size [Integer] Total memory (cgroup limit when in a container, else physical RAM).
12+
# @attribute used_size [Integer] Memory in use (total_size - free_size).
13+
# @attribute free_size [Integer] Available memory (MemAvailable-style: free + reclaimable).
14+
# @attribute swap_total_size [Integer, nil] Total swap, or nil if not available.
15+
# @attribute swap_used_size [Integer, nil] Swap in use, or nil if not available.
16+
Memory = Struct.new(:total_size, :used_size, :free_size, :swap_total_size, :swap_used_size) do
1717
alias as_json to_h
1818

1919
def to_json(*arguments)

lib/process/metrics/memory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def self.zero
3737
# Total system/host memory in bytes. Delegates to Host::Memory.capture.
3838
# @returns [Integer | Nil]
3939
def self.total_size
40-
Host::Memory.capture&.total
40+
Host::Memory.capture&.total_size
4141
end
4242

4343
# Whether the memory usage can be captured on this system.

releases.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Consistent use of `_size` suffix.
6+
37
## v0.10.0
48

5-
- **Host::Memory**: New per-host struct `Process::Metrics::Host::Memory` with `total`, `used`, `free`, `swap_total`, `swap_used` (all bytes). Use `Host::Memory.capture` to get a snapshot; `.supported?` indicates platform support.
9+
- **Host::Memory**: New per-host struct `Process::Metrics::Host::Memory` with `total_size`, `used_size`, `free_size`, `swap_total_size`, `swap_used_size` (all bytes). Use `Host::Memory.capture` to get a snapshot; `.supported?` indicates platform support.
610

711
## v0.9.0
812

test/process/host/memory.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77

88
describe Process::Metrics::Host::Memory do
99
with ".capture" do
10-
it "returns a struct with total, used, free when supported" do
10+
it "returns a struct with total_size, used_size, free_size when supported" do
1111
host = Process::Metrics::Host::Memory.capture
1212
skip "Host::Memory is not available on this platform" unless host
1313
expect(host).to be_a(Process::Metrics::Host::Memory)
14-
expect(host.total).to be_a(Integer)
15-
expect(host.total).to be > 0
16-
expect(host.used).to be_a(Integer)
17-
expect(host.used).to be >= 0
18-
expect(host.free).to be_a(Integer)
19-
expect(host.free).to be >= 0
20-
expect(host.used + host.free).to be == host.total
14+
expect(host.total_size).to be_a(Integer)
15+
expect(host.total_size).to be > 0
16+
expect(host.used_size).to be_a(Integer)
17+
expect(host.used_size).to be >= 0
18+
expect(host.free_size).to be_a(Integer)
19+
expect(host.free_size).to be >= 0
20+
expect(host.used_size + host.free_size).to be == host.total_size
2121
end
2222

23-
it "may include swap_total and swap_used" do
23+
it "may include swap_total_size and swap_used_size" do
2424
host = Process::Metrics::Host::Memory.capture
2525
skip "Host::Memory is not available on this platform" unless host
26-
if host.swap_total
27-
expect(host.swap_total).to be_a(Integer)
28-
expect(host.swap_used).to be_a(Integer) if host.swap_used
26+
if host.swap_total_size
27+
expect(host.swap_total_size).to be_a(Integer)
28+
expect(host.swap_used_size).to be_a(Integer) if host.swap_used_size
2929
end
3030
end
3131

@@ -34,7 +34,7 @@
3434
skip "Host::Memory is not available on this platform" unless host
3535
json = host.to_json
3636
parsed = JSON.parse(json)
37-
expect(parsed).to have_keys("total", "used", "free")
37+
expect(parsed).to have_keys("total_size", "used_size", "free_size")
3838
end
3939
end
4040

0 commit comments

Comments
 (0)