Module: Datadog::Core::Environment::Cgroup

Defined in:
lib/datadog/core/environment/cgroup.rb

Overview

Reads information from Linux cgroups. This information is used to extract information about the current Linux container identity.

Defined Under Namespace

Classes: Descriptor

Constant Summary collapse

LINE_REGEX =
/^(\d+):([^:]*):(.+)$/.freeze

Class Method Summary collapse

Class Method Details

.descriptors(process = 'self') ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/datadog/core/environment/cgroup.rb', line 24

def descriptors(process = 'self')
  [].tap do |descriptors|
    begin
      filepath = "/proc/#{process}/cgroup"

      if File.exist?(filepath)
        File.foreach("/proc/#{process}/cgroup") do |line|
          line = line.strip
          descriptors << parse(line) unless line.empty?
        end
      end
    rescue StandardError => e
      Datadog.logger.error(
        "Error while parsing cgroup. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
      )
    end
  end
end

.parse(line) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/datadog/core/environment/cgroup.rb', line 43

def parse(line)
  id, groups, path = line.scan(LINE_REGEX).first

  Descriptor.new(id, groups, path).tap do |descriptor|
    descriptor.controllers = groups.split(',') unless groups.nil?
  end
end