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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datadog/core/environment/cgroup.rb', line 22 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.} Location: #{Array(e.backtrace).first}" ) end end end |
.parse(line) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/datadog/core/environment/cgroup.rb', line 41 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 |