Sha256: 2fc80c948f5a23591ecc77f21c94c57fe9b85ddf9a3123955cfad3b2be1794a2

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

module OneApm
  module Collector
    class ShellPoller

      attr_accessor :pid

      def memory
        pids.inject(0.0){|m, pid| m + get_memory_by_pid(pid) }
      end

      def cpu_utilization
        @pid = Process.pid
        ps_float('%cpu') / 100.0
      end

      def to_s
        "ShellPoller from: ps -p #{pid}"
      end

      def self.kb_page_size
        @size ||= `getconf PAGE_SIZE`.to_f / 1024.0 rescue 4.0
      end

      protected

      def pgrp_id
        Process.getpgrp
      end

      def pids_cmd
        `ps -o pid,pgid -e | grep -w "#{pgrp_id}"`
      end

      def pids
        @pids = pids_cmd.split(/\s+/).uniq rescue [Process.pid.to_s]
        @pids = [Process.pid.to_s] if @pids.empty?  
        @pids
      end

      def get_memory_by_pid pid
        return 0.0 if pid.empty?
        @pid = pid
        poll_memory rescue 0.0
      end

      def poll_memory
        ps_float('rss') / 1024.0
      end

      def ps_float keyword
        `ps -o #{keyword}= -p #{pid}`.to_f
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.4.1 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.4.0 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.7 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.6 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.5 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.4 lib/one_apm/collector/support/shell_poller.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/collector/support/shell_poller.rb