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.


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

def initialize
  clear
  setup_expire
end

Instance Attribute Details

#expireObject (readonly)

Returns the value of attribute expire


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

def expire
  @expire
end

Instance Method Details

#children(pid) ⇒ Object


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

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

#clearObject


74
75
76
77
78
# File 'lib/eye/system_resources.rb', line 74

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

#proc_cpu(pid) ⇒ Object


86
87
88
89
90
# File 'lib/eye/system_resources.rb', line 86

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

rescue ArgumentError # when incorrect PID
end

#proc_mem(pid) ⇒ Object


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

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

rescue ArgumentError # when incorrect PID
end

#setup_expire(expire = 5) ⇒ Object


68
69
70
71
72
# File 'lib/eye/system_resources.rb', line 68

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