Class: Eye::SystemResources
Defined Under Namespace
Classes: Cache
Class Method Summary collapse
- .cache ⇒ Object
- .children(parent_pid) ⇒ Object
- .cpu(pid) ⇒ Object
-
.cputime(pid) ⇒ Object
total cpu usage in seconds.
- .deep_children(pid) ⇒ Object
-
.leaf_child(pid) ⇒ Object
last child in a children tree.
- .memory(pid) ⇒ Object
- .pid_or_children(pid) ⇒ Object
- .resources(pid) ⇒ Object
-
.start_time(pid) ⇒ Object
unixtime.
Class Method Details
.cache ⇒ Object
68 69 70 |
# File 'lib/eye/system_resources.rb', line 68 def cache Celluloid::Actor[:system_resources_cache] end |
.children(parent_pid) ⇒ Object
20 21 22 |
# File 'lib/eye/system_resources.rb', line 20 def children(parent_pid) cache.children(parent_pid) end |
.cpu(pid) ⇒ Object
14 15 16 17 18 |
# File 'lib/eye/system_resources.rb', line 14 def cpu(pid) if cpu = cache.proc_cpu(pid) cpu.percent * 100 end end |
.cputime(pid) ⇒ Object
total cpu usage in seconds
31 32 33 34 35 |
# File 'lib/eye/system_resources.rb', line 31 def cputime(pid) if cpu = cache.proc_cpu(pid) cpu.total.to_f / 1000 end end |
.deep_children(pid) ⇒ Object
47 48 49 |
# File 'lib/eye/system_resources.rb', line 47 def deep_children(pid) Array(pid_or_children(pid)).flatten.sort_by { |pid| -pid } end |
.leaf_child(pid) ⇒ Object
last child in a children tree
38 39 40 41 42 43 44 45 |
# File 'lib/eye/system_resources.rb', line 38 def leaf_child(pid) if dc = deep_children(pid) dc.detect do |child| args = Eye::Sigar.proc_args(child)[0] rescue '' !args.start_with?('logger') && child != pid end end end |
.memory(pid) ⇒ Object
8 9 10 11 12 |
# File 'lib/eye/system_resources.rb', line 8 def memory(pid) if mem = cache.proc_mem(pid) mem.resident end end |
.pid_or_children(pid) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/eye/system_resources.rb', line 51 def pid_or_children(pid) c = children(pid) if !c || c.empty? pid else c.map { |ppid| pid_or_children(ppid) } end end |
.resources(pid) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/eye/system_resources.rb', line 60 def resources(pid) { :memory => memory(pid), :cpu => cpu(pid), :start_time => start_time(pid), :pid => pid } end |
.start_time(pid) ⇒ Object
unixtime
24 25 26 27 28 |
# File 'lib/eye/system_resources.rb', line 24 def start_time(pid) # unixtime if cpu = cache.proc_cpu(pid) cpu.start_time.to_i / 1000 end end |