Class: Harness::Counter
- Inherits:
-
Measurement
- Object
- Measurement
- Harness::Counter
- Defined in:
- lib/harness/counter.rb
Instance Attribute Summary
Attributes inherited from Measurement
#id, #name, #source, #time, #units, #value
Class Method Summary collapse
Methods inherited from Measurement
#attributes, #initialize, #log
Constructor Details
This class inherits a constructor from Harness::Measurement
Class Method Details
.from_event(event) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/harness/counter.rb', line 5 def self.from_event(event) if event.payload[:counter].is_a? Hash counter = new event.payload[:counter] elsif event.payload[:counter].is_a?(Symbol) || event.payload[:counter].is_a?(String) counter = new :id => event.payload[:counter].to_s else counter = new end counter.id ||= event.name Harness.redis.sadd 'counters', counter.id if event.payload[:counter].is_a? Fixnum counter.value = event.payload[:counter] end if counter.value Harness.redis.set counter.id, counter.value else counter.value = Harness.redis.incr(counter.id).to_i end Harness.redis.zadd "meters/#{counter.id}", counter.time.to_f, counter.value counter end |