Class: StatsdServer::Input::ZeroMQ
- Inherits:
-
Object
- Object
- StatsdServer::Input::ZeroMQ
- Defined in:
- lib/statsdserver/input/zeromq.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
-
#initialize ⇒ ZeroMQ
constructor
A new instance of ZeroMQ.
- #on_readable(socket, parts) ⇒ Object
- #receive_data(packet) ⇒ Object
Constructor Details
#initialize ⇒ ZeroMQ
Returns a new instance of ZeroMQ.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/statsdserver/input/zeromq.rb', line 11 def initialize begin require "em-zeromq" rescue LoadError => e raise unless e. =~ /em-zeromq/ new_e = \ e.exception("Please install the em-zeromq gem for ZeroMQ input.") new_e.set_backtrace(e.backtrace) raise new_e end @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/statsdserver/input/zeromq.rb', line 7 def logger @logger end |
#stats ⇒ Object
Returns the value of attribute stats.
7 8 9 |
# File 'lib/statsdserver/input/zeromq.rb', line 7 def stats @stats end |
Instance Method Details
#on_readable(socket, parts) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/statsdserver/input/zeromq.rb', line 26 def on_readable(socket, parts) parts.each do |part| str = part.copy_out_string receive_data(str) end end |
#receive_data(packet) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/statsdserver/input/zeromq.rb', line 34 def receive_data(packet) raise "@stats must be set" unless @stats sep = packet.index(";") if sep.nil? @logger.warn("received unversioned update: #{packet}") return end proto_ver = packet[0 .. sep - 1] payload = packet[sep + 1 .. -1] case proto_ver when "1" begin StatsdServer::Proto::V1.parse(payload, @stats) rescue StatsdServer::Proto::ParseError => e @logger.warn(e.) end else @logger.warn("unknown protocol version #{proto_ver} in update #{packet}") return end end |