Class: Process::Metrics::Host::Memory
- Inherits:
-
Struct
- Object
- Struct
- Process::Metrics::Host::Memory
- Defined in:
- lib/process/metrics/host/memory.rb
Overview
Struct for host memory snapshot. All sizes in bytes. Stored: total_size, used_size, swap_*, reclaimable_size. free_size and available_size are derived.
Defined Under Namespace
Modules: Linux Classes: Darwin
Instance Attribute Summary collapse
-
#reclaimable_size ⇒ Object
readonly
Reclaimable memory (e.g. page cache, slab), or nil.
-
#swap_total_size ⇒ Object
readonly
Total swap, or nil if not available.
-
#swap_used_size ⇒ Object
readonly
Swap in use, or nil if not available.
-
#total_size ⇒ Object
readonly
Total memory (cgroup limit when in a container, else physical RAM).
-
#used_size ⇒ Object
readonly
Memory in use (kernel/cgroup view; on Linux includes reclaimable e.g. page cache).
Class Method Summary collapse
-
.capture ⇒ Object
Capture current host memory.
-
.supported? ⇒ Boolean
Whether host memory capture is supported on this platform.
-
.zero ⇒ Object
Create a zero-initialized Host::Memory instance.
Instance Method Summary collapse
-
#available_size ⇒ Object
Memory that could be used: free_size plus reclaimable.
-
#free_size ⇒ Object
Complement of used: total_size - used_size.
-
#to_h ⇒ Object
(also: #as_json)
Convert the memory snapshot to a hash, including derived sizes.
-
#to_json(*arguments) ⇒ Object
Convert the memory snapshot to JSON.
Instance Attribute Details
#reclaimable_size ⇒ Object (readonly)
Reclaimable memory (e.g. page cache, slab), or nil. Included in used_size.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/process/metrics/host/memory.rb', line 17 Memory = Struct.new(:total_size, :used_size, :swap_total_size, :swap_used_size, :reclaimable_size) do # Convert the memory snapshot to a hash, including derived sizes. # @returns [Hash(Symbol, Integer | Nil)] The memory snapshot fields. def to_h super.merge(free_size: free_size, available_size: available_size) end alias as_json to_h # Convert the memory snapshot to JSON. # @parameter arguments [Array] Additional arguments passed to the JSON encoder. # @returns [String] The encoded memory snapshot. def to_json(*arguments) as_json.to_json(*arguments) end # Complement of used: total_size - used_size. Same meaning on all platforms. def free_size total_size - used_size end # Memory that could be used: free_size plus reclaimable. Use this for "available" when reclaimable_size is set; otherwise equals free_size. def available_size free_size + (reclaimable_size || 0) end # Create a zero-initialized Host::Memory instance. # @returns [Memory] def self.zero self.new(0, 0, nil, nil, nil) end # Whether host memory capture is supported on this platform. # @returns [Boolean] def self.supported? false end # Capture current host memory. Implemented by Host::Memory::Linux or Host::Memory::Darwin (in host/memory/linux.rb, host/memory/darwin.rb). # @returns [Memory | Nil] A Host::Memory instance, or nil if not supported or capture failed. def self.capture return nil end end |
#swap_total_size ⇒ Object (readonly)
Total swap, or nil if not available.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/process/metrics/host/memory.rb', line 17 Memory = Struct.new(:total_size, :used_size, :swap_total_size, :swap_used_size, :reclaimable_size) do # Convert the memory snapshot to a hash, including derived sizes. # @returns [Hash(Symbol, Integer | Nil)] The memory snapshot fields. def to_h super.merge(free_size: free_size, available_size: available_size) end alias as_json to_h # Convert the memory snapshot to JSON. # @parameter arguments [Array] Additional arguments passed to the JSON encoder. # @returns [String] The encoded memory snapshot. def to_json(*arguments) as_json.to_json(*arguments) end # Complement of used: total_size - used_size. Same meaning on all platforms. def free_size total_size - used_size end # Memory that could be used: free_size plus reclaimable. Use this for "available" when reclaimable_size is set; otherwise equals free_size. def available_size free_size + (reclaimable_size || 0) end # Create a zero-initialized Host::Memory instance. # @returns [Memory] def self.zero self.new(0, 0, nil, nil, nil) end # Whether host memory capture is supported on this platform. # @returns [Boolean] def self.supported? false end # Capture current host memory. Implemented by Host::Memory::Linux or Host::Memory::Darwin (in host/memory/linux.rb, host/memory/darwin.rb). # @returns [Memory | Nil] A Host::Memory instance, or nil if not supported or capture failed. def self.capture return nil end end |
#swap_used_size ⇒ Object (readonly)
Swap in use, or nil if not available.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/process/metrics/host/memory.rb', line 17 Memory = Struct.new(:total_size, :used_size, :swap_total_size, :swap_used_size, :reclaimable_size) do # Convert the memory snapshot to a hash, including derived sizes. # @returns [Hash(Symbol, Integer | Nil)] The memory snapshot fields. def to_h super.merge(free_size: free_size, available_size: available_size) end alias as_json to_h # Convert the memory snapshot to JSON. # @parameter arguments [Array] Additional arguments passed to the JSON encoder. # @returns [String] The encoded memory snapshot. def to_json(*arguments) as_json.to_json(*arguments) end # Complement of used: total_size - used_size. Same meaning on all platforms. def free_size total_size - used_size end # Memory that could be used: free_size plus reclaimable. Use this for "available" when reclaimable_size is set; otherwise equals free_size. def available_size free_size + (reclaimable_size || 0) end # Create a zero-initialized Host::Memory instance. # @returns [Memory] def self.zero self.new(0, 0, nil, nil, nil) end # Whether host memory capture is supported on this platform. # @returns [Boolean] def self.supported? false end # Capture current host memory. Implemented by Host::Memory::Linux or Host::Memory::Darwin (in host/memory/linux.rb, host/memory/darwin.rb). # @returns [Memory | Nil] A Host::Memory instance, or nil if not supported or capture failed. def self.capture return nil end end |
#total_size ⇒ Object (readonly)
Total memory (cgroup limit when in a container, else physical RAM).
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/process/metrics/host/memory.rb', line 17 Memory = Struct.new(:total_size, :used_size, :swap_total_size, :swap_used_size, :reclaimable_size) do # Convert the memory snapshot to a hash, including derived sizes. # @returns [Hash(Symbol, Integer | Nil)] The memory snapshot fields. def to_h super.merge(free_size: free_size, available_size: available_size) end alias as_json to_h # Convert the memory snapshot to JSON. # @parameter arguments [Array] Additional arguments passed to the JSON encoder. # @returns [String] The encoded memory snapshot. def to_json(*arguments) as_json.to_json(*arguments) end # Complement of used: total_size - used_size. Same meaning on all platforms. def free_size total_size - used_size end # Memory that could be used: free_size plus reclaimable. Use this for "available" when reclaimable_size is set; otherwise equals free_size. def available_size free_size + (reclaimable_size || 0) end # Create a zero-initialized Host::Memory instance. # @returns [Memory] def self.zero self.new(0, 0, nil, nil, nil) end # Whether host memory capture is supported on this platform. # @returns [Boolean] def self.supported? false end # Capture current host memory. Implemented by Host::Memory::Linux or Host::Memory::Darwin (in host/memory/linux.rb, host/memory/darwin.rb). # @returns [Memory | Nil] A Host::Memory instance, or nil if not supported or capture failed. def self.capture return nil end end |
#used_size ⇒ Object (readonly)
Memory in use (kernel/cgroup view; on Linux includes reclaimable e.g. page cache).
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/process/metrics/host/memory.rb', line 17 Memory = Struct.new(:total_size, :used_size, :swap_total_size, :swap_used_size, :reclaimable_size) do # Convert the memory snapshot to a hash, including derived sizes. # @returns [Hash(Symbol, Integer | Nil)] The memory snapshot fields. def to_h super.merge(free_size: free_size, available_size: available_size) end alias as_json to_h # Convert the memory snapshot to JSON. # @parameter arguments [Array] Additional arguments passed to the JSON encoder. # @returns [String] The encoded memory snapshot. def to_json(*arguments) as_json.to_json(*arguments) end # Complement of used: total_size - used_size. Same meaning on all platforms. def free_size total_size - used_size end # Memory that could be used: free_size plus reclaimable. Use this for "available" when reclaimable_size is set; otherwise equals free_size. def available_size free_size + (reclaimable_size || 0) end # Create a zero-initialized Host::Memory instance. # @returns [Memory] def self.zero self.new(0, 0, nil, nil, nil) end # Whether host memory capture is supported on this platform. # @returns [Boolean] def self.supported? false end # Capture current host memory. Implemented by Host::Memory::Linux or Host::Memory::Darwin (in host/memory/linux.rb, host/memory/darwin.rb). # @returns [Memory | Nil] A Host::Memory instance, or nil if not supported or capture failed. def self.capture return nil end end |
Class Method Details
.capture ⇒ Object
Capture current host memory. Implemented by Host::Memory::Linux or Host::Memory::Darwin (in host/memory/linux.rb, host/memory/darwin.rb).
57 58 59 |
# File 'lib/process/metrics/host/memory.rb', line 57 def self.capture return nil end |
.supported? ⇒ Boolean
Whether host memory capture is supported on this platform.
51 52 53 |
# File 'lib/process/metrics/host/memory.rb', line 51 def self.supported? false end |
.zero ⇒ Object
Create a zero-initialized Host::Memory instance.
45 46 47 |
# File 'lib/process/metrics/host/memory.rb', line 45 def self.zero self.new(0, 0, nil, nil, nil) end |
Instance Method Details
#available_size ⇒ Object
Memory that could be used: free_size plus reclaimable. Use this for "available" when reclaimable_size is set; otherwise equals free_size.
39 40 41 |
# File 'lib/process/metrics/host/memory.rb', line 39 def available_size free_size + (reclaimable_size || 0) end |
#free_size ⇒ Object
Complement of used: total_size - used_size. Same meaning on all platforms.
34 35 36 |
# File 'lib/process/metrics/host/memory.rb', line 34 def free_size total_size - used_size end |
#to_h ⇒ Object Also known as: as_json
Convert the memory snapshot to a hash, including derived sizes.
20 21 22 |
# File 'lib/process/metrics/host/memory.rb', line 20 def to_h super.merge(free_size: free_size, available_size: available_size) end |
#to_json(*arguments) ⇒ Object
Convert the memory snapshot to JSON.
29 30 31 |
# File 'lib/process/metrics/host/memory.rb', line 29 def to_json(*arguments) as_json.to_json(*arguments) end |