Class: Eye::SystemResources

Inherits:
Object show all
Defined in:
lib/eye/system_resources.rb

Defined Under Namespace

Classes: Cache

Class Method Summary collapse

Class Method Details

.cacheObject


53
54
55
# File 'lib/eye/system_resources.rb', line 53

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

.leaf_child(pid) ⇒ Object

last child in a children tree


38
39
40
41
42
43
# File 'lib/eye/system_resources.rb', line 38

def leaf_child(pid)
  c = children(pid)
  return if c.empty?
  c += children(c.shift) while c.size > 1
  c[0]
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

.resources(pid) ⇒ Object


45
46
47
48
49
50
51
# File 'lib/eye/system_resources.rb', line 45

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