Class: Freyr::ProcessInfo
- Inherits:
-
Object
- Object
- Freyr::ProcessInfo
- Defined in:
- lib/freyr/process_info.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#pcpu ⇒ Object
readonly
Returns the value of attribute pcpu.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#pmem ⇒ Object
readonly
Returns the value of attribute pmem.
-
#rss ⇒ Object
readonly
Returns the value of attribute rss.
-
#ruser ⇒ Object
readonly
Returns the value of attribute ruser.
-
#vsz ⇒ Object
readonly
Returns the value of attribute vsz.
Class Method Summary collapse
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(pid) ⇒ ProcessInfo
constructor
A new instance of ProcessInfo.
- #mem_in_mb ⇒ Object
- #port ⇒ Object
- #ps ⇒ Object
Constructor Details
#initialize(pid) ⇒ ProcessInfo
Returns a new instance of ProcessInfo.
4 5 6 |
# File 'lib/freyr/process_info.rb', line 4 def initialize pid @pid = pid end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def command @command end |
#pcpu ⇒ Object (readonly)
Returns the value of attribute pcpu.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def pcpu @pcpu end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def pid @pid end |
#pmem ⇒ Object (readonly)
Returns the value of attribute pmem.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def pmem @pmem end |
#rss ⇒ Object (readonly)
Returns the value of attribute rss.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def rss @rss end |
#ruser ⇒ Object (readonly)
Returns the value of attribute ruser.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def ruser @ruser end |
#vsz ⇒ Object (readonly)
Returns the value of attribute vsz.
3 4 5 |
# File 'lib/freyr/process_info.rb', line 3 def vsz @vsz end |
Class Method Details
.[](*args) ⇒ Object
42 43 44 45 |
# File 'lib/freyr/process_info.rb', line 42 def [] *args n = new(*args) n.ps ? n : nil end |
Instance Method Details
#alive? ⇒ Boolean
8 9 10 11 12 13 |
# File 'lib/freyr/process_info.rb', line 8 def alive? Process.getpgid(pid) true rescue Errno::ESRCH false end |
#mem_in_mb ⇒ Object
37 38 39 |
# File 'lib/freyr/process_info.rb', line 37 def mem_in_mb @rss/1024.0 end |
#port ⇒ Object
31 32 33 34 35 |
# File 'lib/freyr/process_info.rb', line 31 def port `lsof -p #{pid} -P | egrep TCP.+LISTEN`.match(/\*:(\d+)/)[1].to_i rescue nil end |
#ps ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/freyr/process_info.rb', line 15 def ps return if !pid || pid.to_s.empty? @ps_info ||= begin info = `ps p #{pid} -o pid,rss,vsz,pmem,pcpu,ruser,command` match = info.match(/#{pid}\s+(\d+)\s+(\d+)\s+([\d\.]+)\s+([\d\.]+)\s+(\w+)\s+(.+)/) return unless match @rss = match[1].to_i @vsz = match[2].to_i @pmem = match[3].to_f @pcpu = match[4].to_f @ruser = match[5] @command = match[6] info end end |