class Metrux::Plugins::Process

Attributes

pid[R]

Public Class Methods

new(*) click to toggle source
Calls superclass method Metrux::Plugins::PeriodicGauge::new
# File lib/metrux/plugins/process.rb, line 4
def initialize(*)
  super
  @pid = ::Process.pid
end

Public Instance Methods

data() click to toggle source
# File lib/metrux/plugins/process.rb, line 9
def data
  { rss: rss }
end
key() click to toggle source
# File lib/metrux/plugins/process.rb, line 13
def key
  'process'.freeze
end

Private Instance Methods

default_rss() click to toggle source
# File lib/metrux/plugins/process.rb, line 38
def default_rss
  exec("ps -o rss= -p #{pid}").chomp.to_i
rescue
  0
end
exec(cmd) click to toggle source
# File lib/metrux/plugins/process.rb, line 66
def exec(cmd)
  ::Kernel.public_send(:`, cmd)
end
fetch_pagesize() click to toggle source
# File lib/metrux/plugins/process.rb, line 60
def fetch_pagesize
  exec('getconf PAGESIZE').chomp.to_i
rescue
  4_096
end
fetch_statm_rss() click to toggle source
# File lib/metrux/plugins/process.rb, line 56
def fetch_statm_rss
  ::File.read(statm_path).split(' ')[1].to_i
end
kernel_page_size() click to toggle source
# File lib/metrux/plugins/process.rb, line 44
def kernel_page_size
  @kernel_page_size ||= fetch_pagesize
end
linux_rss() click to toggle source
# File lib/metrux/plugins/process.rb, line 32
def linux_rss
  statm? ? (fetch_statm_rss * kernel_page_size) / 1_024 : default_rss
rescue
  0
end
rss() click to toggle source
# File lib/metrux/plugins/process.rb, line 21
def rss
  case ::RbConfig::CONFIG['host_os']
  when /darwin|mac os/
    default_rss
  when /linux/
    linux_rss
  else
    0
  end
end
statm?() click to toggle source
# File lib/metrux/plugins/process.rb, line 52
def statm?
  @statm_found ||= ::File.exist?(statm_path)
end
statm_path() click to toggle source
# File lib/metrux/plugins/process.rb, line 48
def statm_path
  @statm_path ||= "/proc/#{pid}/statm".freeze
end