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



51
52
53
# File 'lib/eye/system_resources.rb', line 51

def cache
  @cache ||= Cache.new
end

.children(parent_pid) ⇒ Object



18
19
20
# File 'lib/eye/system_resources.rb', line 18

def children(parent_pid)
  cache.children(parent_pid)
end

.cpu(pid) ⇒ Object



12
13
14
15
16
# File 'lib/eye/system_resources.rb', line 12

def cpu(pid)
  if cpu = cache.proc_cpu(pid)
    cpu.percent * 100
  end
end

.cputime(pid) ⇒ Object

total cpu usage in seconds



29
30
31
32
33
# File 'lib/eye/system_resources.rb', line 29

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



36
37
38
39
40
41
# File 'lib/eye/system_resources.rb', line 36

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
# File 'lib/eye/system_resources.rb', line 8

def memory(pid)
  cache.proc_mem(pid).try(:resident)
end

.resources(pid) ⇒ Object



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

def resources(pid)
  { :memory => memory(pid),
    :cpu => cpu(pid),
    :start_time => start_time(pid),
    :pid => pid
  }
end

.start_time(pid) ⇒ Object

unixtime



22
23
24
25
26
# File 'lib/eye/system_resources.rb', line 22

def start_time(pid) # unixtime
  if cpu = cache.proc_cpu(pid)
    cpu.start_time.to_i / 1000
  end
end