Class: Stalin::Watcher::LinuxProcStatm
- Inherits:
-
Object
- Object
- Stalin::Watcher::LinuxProcStatm
- Defined in:
- lib/stalin/watcher/linux_proc_statm.rb
Overview
Watcher that uses procfs (specifically /proc/<pid>/statm) to determine memory usage.
Instance Method Summary collapse
-
#initialize(pid) ⇒ LinuxProcStatm
constructor
A new instance of LinuxProcStatm.
-
#watch ⇒ Integer?
Report on memory usage.
Constructor Details
#initialize(pid) ⇒ LinuxProcStatm
Returns a new instance of LinuxProcStatm.
6 7 8 9 10 11 12 13 |
# File 'lib/stalin/watcher/linux_proc_statm.rb', line 6 def initialize(pid) @statm = "/proc/%d/statm" % [pid] raise Stalin::Unsupported, "Unreadable or nonexistent file: #{@statm}" unless File.readable?(@statm) page_size = `getconf PAGESIZE` @page_size = Integer(page_size) rescue nil raise Stalin::Unsupported, "Cannot determine page size: #{page_size}" unless $?.success? && @page_size.kind_of?(Integer) end |
Instance Method Details
#watch ⇒ Integer?
Report on memory usage.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stalin/watcher/linux_proc_statm.rb', line 18 def watch vsz, rss, shared = File.read(@statm).split(' ') vsz = Integer(vsz) * @page_size rss = Integer(rss) * @page_size shared = Integer(shared) * @page_size rss rescue SystemCallError # assume any failure means that process has gone away nil end |