Class: PulseMeter::Sensor::Remote
- Defined in:
- lib/pulse-meter/sensor/remote.rb
Overview
Remote sensor, i.e. a simple UDP proxy for sending data without taking in account backend performance issues
Constant Summary collapse
- DEFAULT_PORT =
27182
- DEFAULT_HOST =
'localhost'
Constants included from Mixins::Dumper
Mixins::Dumper::DUMP_REDIS_KEY
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Base
Instance Method Summary collapse
-
#event(value) ⇒ Object
Send value to remote sensor.
-
#events(event_data) ⇒ Object
Send values to multiple remote sensors.
-
#initialize(name, options = {}) ⇒ Remote
constructor
Initializes sensor and creates UDP socket.
Methods inherited from Base
#annotate, #annotation, #cleanup
Methods included from Mixins::Dumper
Constructor Details
#initialize(name, options = {}) ⇒ Remote
Initializes sensor and creates UDP socket
24 25 26 27 28 29 30 |
# File 'lib/pulse-meter/sensor/remote.rb', line 24 def initialize(name, ={}) @name = name.to_s raise BadSensorName, @name unless @name =~ /\A\w+\z/ @host = [:host].to_s || DEFAULT_HOST @port = [:port].to_i || DEFAULT_PORT @socket = UDPSocket.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/pulse-meter/sensor/remote.rb', line 16 def name @name end |
Instance Method Details
#event(value) ⇒ Object
Send value to remote sensor
36 37 38 |
# File 'lib/pulse-meter/sensor/remote.rb', line 36 def event(value) events(name => value) end |
#events(event_data) ⇒ Object
Send values to multiple remote sensors
42 43 44 45 46 47 |
# File 'lib/pulse-meter/sensor/remote.rb', line 42 def events(event_data) raise ArgumentError unless event_data.is_a?(Hash) socket_action do @socket.send(event_data.to_json, 0, @host, @port) end end |