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.


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

def initialize
  clear
  setup_expire
end

Instance Attribute Details

#expireObject (readonly)

Returns the value of attribute expire


82
83
84
# File 'lib/eye/system_resources.rb', line 82

def expire
  @expire
end

Instance Method Details

#children(pid) ⇒ Object


115
116
117
118
119
120
121
# File 'lib/eye/system_resources.rb', line 115

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

#clearObject


95
96
97
98
99
# File 'lib/eye/system_resources.rb', line 95

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

#proc_cpu(pid) ⇒ Object


108
109
110
111
112
113
# File 'lib/eye/system_resources.rb', line 108

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

rescue ArgumentError
  # when incorrect PID, just skip
end

#proc_mem(pid) ⇒ Object


101
102
103
104
105
106
# File 'lib/eye/system_resources.rb', line 101

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

rescue ArgumentError
  # when incorrect PID, just skip
end

#setup_expire(expire = 5) ⇒ Object


89
90
91
92
93
# File 'lib/eye/system_resources.rb', line 89

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