Class: SystemMetrics::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/system_metrics/collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Collector

Returns a new instance of Collector.



5
6
7
# File 'lib/system_metrics/collector.rb', line 5

def initialize(store)
  @store = store
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



3
4
5
# File 'lib/system_metrics/collector.rb', line 3

def store
  @store
end

Instance Method Details

#collectObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/system_metrics/collector.rb', line 13

def collect
  events.clear
  SystemMetrics.collection_on
  result = yield
  SystemMetrics.collection_off
  store.save events.dup
  result
ensure
  SystemMetrics.collection_off
  events.clear
end

#collect_event(event) ⇒ Object



9
10
11
# File 'lib/system_metrics/collector.rb', line 9

def collect_event(event)
  events.push event if SystemMetrics.collecting?
end