Class: Arbi::Modules::Cpu
Instance Attribute Summary
Attributes inherited from Module
#data
Instance Method Summary
collapse
Methods inherited from Module
__method_missing__, #every, inherited, json_create, method_missing, modules, name, #to_json
Constructor Details
#initialize(data = []) ⇒ Cpu
Returns a new instance of Cpu.
25
26
27
28
29
30
31
32
33
|
# File 'lib/arbi/modules/cpu.rb', line 25
def initialize(data = [])
super(data)
@mutex = Mutex.new
@prev = {:idle => {}, :total => {}}
@datas = []
every 2, :timeout => 10, &self.method(:update)
end
|
Instance Method Details
45
46
47
48
49
|
# File 'lib/arbi/modules/cpu.rb', line 45
def format
tablize([['NAME', 'PERCENT']] + @data.map {|x|
[x[:name] || x['name'], x[:percent] || x['percent']]
})
end
|
#refresh ⇒ Object
39
40
41
42
43
|
# File 'lib/arbi/modules/cpu.rb', line 39
def refresh
@mutex.synchronize {
@data = @datas.dup
}
end
|
#valid? ⇒ Boolean
35
36
37
|
# File 'lib/arbi/modules/cpu.rb', line 35
def valid?
File.exist?('/proc/stat')
end
|