Sha256: dbb067bd8fe066b5f162130cb5599f485de476ac1f0597f1f336d251c71ff95b

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

require_relative 'ext'

module Datadog
  module Core
    module Environment
      # Reads information from Linux cgroups.
      # This information is used to extract information
      # about the current Linux container identity.
      # @see https://man7.org/linux/man-pages/man7/cgroups.7.html
      module Cgroup
        LINE_REGEX = /^(\d+):([^:]*):(.+)$/.freeze

        Descriptor = Struct.new(
          :id,
          :groups,
          :path,
          :controllers
        )

        module_function

        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

        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
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/core/environment/cgroup.rb
ddtrace-1.23.2 lib/datadog/core/environment/cgroup.rb
ddtrace-1.23.1 lib/datadog/core/environment/cgroup.rb
ddtrace-1.22.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.21.1 lib/datadog/core/environment/cgroup.rb
ddtrace-1.21.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.20.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.19.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.18.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.17.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.16.2 lib/datadog/core/environment/cgroup.rb
ddtrace-1.16.1 lib/datadog/core/environment/cgroup.rb
ddtrace-1.16.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.15.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.14.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.13.1 lib/datadog/core/environment/cgroup.rb
ddtrace-1.13.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.12.1 lib/datadog/core/environment/cgroup.rb
ddtrace-1.12.0 lib/datadog/core/environment/cgroup.rb
ddtrace-1.11.1 lib/datadog/core/environment/cgroup.rb