Class: Eye::SystemResources::Cache

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



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

def initialize
  clear
  setup_expire
end

Instance Attribute Details

#expireObject (readonly)

Returns the value of attribute expire.



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

def expire
  @expire
end

Instance Method Details

#children(pid) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/eye/system_resources.rb', line 82

def children(pid)
  if pid
    @ppids[pid] ||= Eye::Sigar.proc_list("State.Ppid.eq=#{pid}")
  else
    []
  end
end

#clearObject



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

def clear
  @memory = {}
  @cpu = {}
  @ppids = {}
end

#proc_cpu(pid) ⇒ Object



76
77
78
79
80
# File 'lib/eye/system_resources.rb', line 76

def proc_cpu(pid)
  @cpu[pid] ||= Eye::Sigar.proc_cpu(pid) if pid

rescue ArgumentError # when incorrect PID
end

#proc_mem(pid) ⇒ Object



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

def proc_mem(pid)
  @memory[pid] ||= Eye::Sigar.proc_mem(pid) if pid

rescue ArgumentError # when incorrect PID
end

#setup_expire(expire = 5) ⇒ Object



58
59
60
61
62
# File 'lib/eye/system_resources.rb', line 58

def setup_expire(expire = 5)
  @expire = expire
  @timer.cancel if @timer
  @timer = every(@expire) { clear }
end