class Eye::SystemResources

Public Class Methods

args(pid) click to toggle source
# File lib/eye/system_resources.rb, line 61
def args(pid)
  Eye::Sigar.proc_args(pid).join(' ').strip rescue '-'
end
cache() click to toggle source
# File lib/eye/system_resources.rb, line 72
def cache
  Celluloid::Actor[:system_resources_cache]
end
children(parent_pid) click to toggle source
# File lib/eye/system_resources.rb, line 20
def children(parent_pid)
  cache.children(parent_pid)
end
cpu(pid) click to toggle source
# File lib/eye/system_resources.rb, line 14
def cpu(pid)
  if cpu = cache.proc_cpu(pid)
    cpu.percent * 100
  end
end
cputime(pid) click to toggle source

total cpu usage in seconds

# 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) click to toggle source
# File lib/eye/system_resources.rb, line 48
def deep_children(pid)
  Array(pid_or_children(pid)).flatten.sort_by(&:-@)
end
leaf_child(pid) click to toggle source

last child in a children tree

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

unixtime

# 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