Class: ServerScripts::MemoryMonitor
- Inherits:
-
Object
- Object
- ServerScripts::MemoryMonitor
- Defined in:
- lib/server_scripts/memory_monitor.rb
Instance Attribute Summary collapse
-
#duration_sec ⇒ Object
readonly
Returns the value of attribute duration_sec.
-
#interval_sec ⇒ Object
readonly
Returns the value of attribute interval_sec.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#pname ⇒ Object
readonly
Returns the value of attribute pname.
-
#vmrss ⇒ Object
readonly
Returns the value of attribute vmrss.
-
#vmsize ⇒ Object
readonly
Returns the value of attribute vmsize.
Instance Method Summary collapse
-
#initialize(pid: nil, pname: nil, duration: "00:00:30", interval: "00:00:01") ⇒ MemoryMonitor
constructor
A new instance of MemoryMonitor.
- #start! ⇒ Object
Constructor Details
#initialize(pid: nil, pname: nil, duration: "00:00:30", interval: "00:00:01") ⇒ MemoryMonitor
Returns a new instance of MemoryMonitor.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/server_scripts/memory_monitor.rb', line 10 def initialize(pid: nil, pname: nil, duration: "00:00:30", interval: "00:00:01") @vmrss = [] @vmsize = [] if pname.nil? && pid @pname = `ps -p #{pid} -o comm=`.strip @pid = pid end if pid.nil? && pname @pname = pname @pid = `pidof #{pname}`.strip.to_i end parse_time_intervals duration, interval end |
Instance Attribute Details
#duration_sec ⇒ Object (readonly)
Returns the value of attribute duration_sec.
5 6 7 |
# File 'lib/server_scripts/memory_monitor.rb', line 5 def duration_sec @duration_sec end |
#interval_sec ⇒ Object (readonly)
Returns the value of attribute interval_sec.
6 7 8 |
# File 'lib/server_scripts/memory_monitor.rb', line 6 def interval_sec @interval_sec end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/server_scripts/memory_monitor.rb', line 3 def pid @pid end |
#pname ⇒ Object (readonly)
Returns the value of attribute pname.
4 5 6 |
# File 'lib/server_scripts/memory_monitor.rb', line 4 def pname @pname end |
#vmrss ⇒ Object (readonly)
Returns the value of attribute vmrss.
7 8 9 |
# File 'lib/server_scripts/memory_monitor.rb', line 7 def vmrss @vmrss end |
#vmsize ⇒ Object (readonly)
Returns the value of attribute vmsize.
8 9 10 |
# File 'lib/server_scripts/memory_monitor.rb', line 8 def vmsize @vmsize end |
Instance Method Details
#start! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/server_scripts/memory_monitor.rb', line 27 def start! @duration_sec.times do file = File.open "/proc/#{@pid}/status" file.each_line do |l| rss = l.match(/VmRSS:\s+(\d+)\s+kB/) @vmrss << (rss[1].to_i / 1e3) if rss size = l.match(/VmSize:\s+(\d+)\s+kB/) @vmsize << (size[1].to_i / 1e3) if size end sleep @interval_sec end end |