Sha256: 118b9c66d0e96de9fe687569aec1d6097768d3f9e36e55dfe1e2e2405f3b9112

Contents?: true

Size: 883 Bytes

Versions: 63

Compression:

Stored size: 883 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

63 entries across 63 versions & 20 rubygems

Version Path
dguettler-god-0.7.13.2 lib/god/system/portable_poller.rb
dguettler-god-0.7.13.3 lib/god/system/portable_poller.rb
dosire-god-0.7.10 lib/god/system/portable_poller.rb
dosire-god-0.7.12 lib/god/system/portable_poller.rb
dosire-god-0.7.9 lib/god/system/portable_poller.rb
dunedain289-god-0.7.12.1 lib/god/system/portable_poller.rb
dustin-god-0.7.7.1 lib/god/system/portable_poller.rb
eric-god-0.7.10 lib/god/system/portable_poller.rb
eric-god-0.7.11 lib/god/system/portable_poller.rb
eric-god-0.7.12 lib/god/system/portable_poller.rb
eric-god-0.7.14 lib/god/system/portable_poller.rb
eric-god-0.7.7 lib/god/system/portable_poller.rb
fotonauts-god-0.7.10 lib/god/system/portable_poller.rb
fotonauts-god-0.7.12 lib/god/system/portable_poller.rb
gohanlonllc-god-0.7.9 lib/god/system/portable_poller.rb
gordoncww-god-0.7.11.1 lib/god/system/portable_poller.rb
jreynolds-god-0.7.13 lib/god/system/portable_poller.rb
jwilkins-god-0.7.9 lib/god/system/portable_poller.rb
mathieuravaux-god-0.7.11 lib/god/system/portable_poller.rb
mojombo-god-0.7.10 lib/god/system/portable_poller.rb