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

.args(pid) ⇒ Object



61
62
63
# File 'lib/eye/system_resources.rb', line 61

def args(pid)
  Eye::Sigar.proc_args(pid).join(' ').strip rescue '-'
end

.cacheObject



72
73
74
# File 'lib/eye/system_resources.rb', line 72

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



32
33
34
35
36
# File 'lib/eye/system_resources.rb', line 32

def cputime(pid)
  if cpu = cache.proc_cpu(pid)
    cpu.total.to_f / 1000
  end
end

.deep_children(pid) ⇒ Object



48
49
50
# File 'lib/eye/system_resources.rb', line 48

def deep_children(pid)
  Array(pid_or_children(pid)).flatten.sort_by(&:-@)
end

.leaf_child(pid) ⇒ Object

last child in a children tree



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

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



52
53
54
55
56
57
58
59
# File 'lib/eye/system_resources.rb', line 52

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



65
66
67
68
69
70
# File 'lib/eye/system_resources.rb', line 65

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

.start_time(pid) ⇒ Object

unixtime



25
26
27
28
29
# File 'lib/eye/system_resources.rb', line 25

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