Class: Process::Metrics::Host::Memory::Linux::CgroupV1
- Inherits:
-
Object
- Object
- Process::Metrics::Host::Memory::Linux::CgroupV1
- Defined in:
- lib/process/metrics/host/memory/linux/cgroup_v1.rb
Overview
Captures host memory limits and usage from a cgroup v1 filesystem.
Constant Summary collapse
- CGROUP_V1_UNLIMITED_THRESHOLD =
2**60
- DEFAULT_CGROUP_ROOT =
"/sys/fs/cgroup"
Class Method Summary collapse
-
.supported?(cgroup_root = DEFAULT_CGROUP_ROOT) ⇒ Boolean
Whether cgroup v1 memory metrics are available.
Instance Method Summary collapse
-
#capture ⇒ Object
Capture host memory from the cgroup v1 filesystem.
-
#initialize(cgroup_root: nil) ⇒ CgroupV1
constructor
Initialize the cgroup v1 memory reader.
Constructor Details
#initialize(cgroup_root: nil) ⇒ CgroupV1
Initialize the cgroup v1 memory reader.
29 30 31 |
# File 'lib/process/metrics/host/memory/linux/cgroup_v1.rb', line 29 def initialize(cgroup_root: nil) @cgroup_root = (cgroup_root || DEFAULT_CGROUP_ROOT).to_s.chomp("/") end |
Class Method Details
.supported?(cgroup_root = DEFAULT_CGROUP_ROOT) ⇒ Boolean
Whether cgroup v1 memory metrics are available.
17 18 19 20 21 22 23 24 25 |
# File 'lib/process/metrics/host/memory/linux/cgroup_v1.rb', line 17 def self.supported?(cgroup_root = DEFAULT_CGROUP_ROOT) root = (cgroup_root || DEFAULT_CGROUP_ROOT).to_s.chomp("/") if File.exist?("#{root}/memory/memory.limit_in_bytes") && File.exist?("#{root}/memory/memory.usage_in_bytes") return true end return false end |
Instance Method Details
#capture ⇒ Object
Capture host memory from the cgroup v1 filesystem.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/process/metrics/host/memory/linux/cgroup_v1.rb', line 35 def capture total = read_total return nil unless total && total.positive? used = read_used return nil unless used used = 0 if used.negative? used = [used, total].min swap_total, swap_used = read_swap reclaimable = read_reclaimable return Host::Memory.new(total, used, swap_total, swap_used, reclaimable) end |