Class: PulseMeter::Sensor::Counter
- Defined in:
- lib/pulse-meter/sensor/counter.rb
Direct Known Subclasses
Constant Summary
Constants included from Mixins::Dumper
Mixins::Dumper::DUMP_REDIS_KEY
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleans up all sensor metadata in Redis.
-
#event(value) ⇒ Object
Processes event by incremnting counter by given value.
-
#incr ⇒ Object
Increments counter value by 1.
-
#value ⇒ Fixnum
Gets counter value.
-
#value_key ⇒ String
Gets redis key by which counter value is stored.
Methods inherited from Base
#annotate, #annotation, #initialize
Methods included from Mixins::Dumper
Constructor Details
This class inherits a constructor from PulseMeter::Sensor::Base
Instance Method Details
#cleanup ⇒ Object
Cleans up all sensor metadata in Redis
7 8 9 10 |
# File 'lib/pulse-meter/sensor/counter.rb', line 7 def cleanup redis.del(value_key) super end |
#event(value) ⇒ Object
Processes event by incremnting counter by given value
19 20 21 |
# File 'lib/pulse-meter/sensor/counter.rb', line 19 def event(value) redis.incrby(value_key, value.to_i) end |
#incr ⇒ Object
Increments counter value by 1
13 14 15 |
# File 'lib/pulse-meter/sensor/counter.rb', line 13 def incr event(1) end |
#value ⇒ Fixnum
Gets counter value
25 26 27 |
# File 'lib/pulse-meter/sensor/counter.rb', line 25 def value redis.get(value_key).to_i end |
#value_key ⇒ String
Gets redis key by which counter value is stored
31 32 33 |
# File 'lib/pulse-meter/sensor/counter.rb', line 31 def value_key @value_key ||= "pulse_meter:value:#{name}" end |