Sha256: e1f18f909eb3c778a8ce81399dd2758182147af6b3b1a58d8fe7439a258c94dc

Contents?: true

Size: 842 Bytes

Versions: 12

Compression:

Stored size: 842 Bytes

Contents

module God
  module System
    class PortablePoller
      def initialize(pid)
        @pid = pid
      end
      # Memory usage in kilobytes (resident set size)
      def memory
        ps_int('rss')
      end

      # Percentage memory usage
      def percent_memory
        ps_float('%mem')
      end

      # Percentage CPU usage
      def percent_cpu
        ps_float('%cpu')
      end

      private

      def ps_int(keyword)
        `ps -o #{keyword}= -p #{@pid}`.to_i
      end

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

      def ps_string(keyword)
        `ps -o #{keyword}= -p #{@pid}`.strip
      end

      def time_string_to_seconds(text)
        _, minutes, seconds, useconds = *text.match(/(\d+):(\d{2}).(\d{2})/)
        (minutes.to_i * 60) + seconds.to_i
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
resurrected_god-0.14.0 lib/god/system/portable_poller.rb
mcproc-2016.2.20 lib/god/system/portable_poller.rb
god-0.13.7 lib/god/system/portable_poller.rb
god-0.13.6 lib/god/system/portable_poller.rb
god-0.13.5 lib/god/system/portable_poller.rb
god-0.13.4 lib/god/system/portable_poller.rb
god-0.13.3 lib/god/system/portable_poller.rb
god-0.13.2 lib/god/system/portable_poller.rb
god-0.13.1 lib/god/system/portable_poller.rb
god-0.13.0 lib/god/system/portable_poller.rb
god-0.12.1 lib/god/system/portable_poller.rb
god-0.12.0 lib/god/system/portable_poller.rb