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.



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

def initialize
  clear
  setup_expire
end

Instance Attribute Details

#expireObject (readonly)

Returns the value of attribute expire.



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

def expire
  @expire
end

Instance Method Details

#children(pid) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/eye/system_resources.rb', line 90

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

#clearObject



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

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

#proc_cpu(pid) ⇒ Object



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

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

rescue ArgumentError # when incorrect PID
end

#proc_mem(pid) ⇒ Object



78
79
80
81
82
# File 'lib/eye/system_resources.rb', line 78

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

rescue ArgumentError # when incorrect PID
end

#setup_expire(expire = 5) ⇒ Object



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

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