Sha256: 23ca1429ef94266fecd46891e42abd64c60568b9cecfd4aa97fe1edc0a3096f1

Contents?: true

Size: 1.49 KB

Versions: 21

Compression:

Stored size: 1.49 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

module Instana
  module Backend
    # Wrapper around {Sys::ProcTable} that adds support for reading the /proc
    # file system for extra information around containers
    # @since 1.197.0
    class ProcessInfo < SimpleDelegator
      def name
        cmdline
          .split(' ').first
      end

      def arguments
        _, *arguments = cmdline.split(' ')
        clean_arguments(arguments)
      end

      def parent_pid
        if in_container? && !sched_pid.nil?
          sched_pid
        else
          pid
        end
      end

      def from_parent_namespace
        !in_container? || in_container? && sched_pid != pid
      end

      def cpuset
        path = "/proc/#{pid}/cpuset"
        return unless File.exist?(path)

        File.read(path).strip
      end

      def in_container?
        !cpuset.nil? && cpuset != '/'
      end

      def sched_pid
        path = '/proc/self/sched'
        return unless File.exist?(path)

        File.read(path).match(/\d+/).to_s.to_i
      end

      def memory_used
        if RbConfig::CONFIG['host_os'].include?('darwin')
          rss
        else
          rss * 4096
        end
      end

      private

      def clean_arguments(arguments)
        return arguments unless RbConfig::CONFIG['host_os'].include?('darwin')

        arguments.reject do |a|
          if a.include?('=')
            k, = a.split('=', 2)
            ENV[k]
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
instana-1.217.1 lib/instana/backend/process_info.rb
instana-1.217.0 lib/instana/backend/process_info.rb
instana-1.216.0 lib/instana/backend/process_info.rb
instana-1.215.1 lib/instana/backend/process_info.rb
instana-1.215.0 lib/instana/backend/process_info.rb
instana-1.214.4 lib/instana/backend/process_info.rb
instana-1.214.3 lib/instana/backend/process_info.rb
instana-1.214.2 lib/instana/backend/process_info.rb
instana-1.214.1 lib/instana/backend/process_info.rb
instana-1.214.0 lib/instana/backend/process_info.rb
instana-1.213.3 lib/instana/backend/process_info.rb
instana-1.213.2 lib/instana/backend/process_info.rb
instana-1.213.1 lib/instana/backend/process_info.rb
instana-1.213.0 lib/instana/backend/process_info.rb
instana-1.212.0 lib/instana/backend/process_info.rb
instana-1.211.0 lib/instana/backend/process_info.rb
instana-1.210.1 lib/instana/backend/process_info.rb
instana-1.210.0 lib/instana/backend/process_info.rb
instana-1.209.8 lib/instana/backend/process_info.rb
instana-1.209.7 lib/instana/backend/process_info.rb