Sha256: 0320b3f08600098f0a0fb08842a3fd8c365160f1ea21055b416a7b62b785dac6

Contents?: true

Size: 958 Bytes

Versions: 6

Compression:

Stored size: 958 Bytes

Contents

module Collectd
  ##
  # Included by Interface
  module ProcStats
    def process_status(field)
      fields = {}
      begin
        IO.readlines("/proc/#{$$}/status").each { |line|
          line.strip!
          if line =~ /^(.+?):\s+(.+)$/
            fields[$1] = $2
          end
        }
      rescue Errno::ENOENT
        nil
      else
        fields[field]
      end
    end

    def with_polled_memory
      memory('VmRSS').polled_gauge do
        (v = process_status('VmRSS')) ? v.to_i * 1024 : nil
      end
      memory('VmSize').polled_gauge do
        (v = process_status('VmSize')) ? v.to_i * 1024 : nil
      end

      self
    end

    def with_polled_cpu
      cpu('user').polled_counter do
        (Process::times.utime * 100).to_i
      end
      cpu('system').polled_counter do
        (Process::times.stime * 100).to_i
      end
    end

    def with_full_proc_stats
      with_polled_memory
      with_polled_cpu
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
astro-collectd-0.0.10 lib/collectd/proc_stats.rb
astro-collectd-0.0.11 lib/collectd/proc_stats.rb
astro-collectd-0.0.12 lib/collectd/proc_stats.rb
astro-collectd-0.0.9 lib/collectd/proc_stats.rb
collectd-0.0.15 lib/collectd/proc_stats.rb
collectd-0.0.12 lib/collectd/proc_stats.rb