Module: Batsd::Receiver
- Defined in:
- lib/batsd/receiver.rb
Overview
Receives and processes incoming statsd measures via UDP
Controls flush timing for each of the handlers.
Defined Under Namespace
Classes: Daemon
Class Method Summary (collapse)
-
+ (Object) handlers
Exposes registered handlers.
-
+ (Object) handlers=(handlers)
Register an array of handlers.
Instance Method Summary (collapse)
-
- (Object) post_init
Startup message after server is launched.
-
- (Object) receive_data(msg)
Receive and handle an incoming UDP message.
Class Method Details
+ (Object) handlers
Exposes registered handlers
11 12 13 |
# File 'lib/batsd/receiver.rb', line 11 def self.handlers @handlers end |
+ (Object) handlers=(handlers)
Register an array of handlers
16 17 18 |
# File 'lib/batsd/receiver.rb', line 16 def self.handlers=(handlers) @handlers = handlers end |
Instance Method Details
- (Object) post_init
Startup message after server is launched
21 22 23 24 |
# File 'lib/batsd/receiver.rb', line 21 def post_init puts "#{Time.now}: batsd receiver is running and knows how to handle " + Batsd::Receiver.handlers.collect{|k, v| k }.join(", ") end |
- (Object) receive_data(msg)
Receive and handle an incoming UDP message
-
Split it into the key, value, type, and sample rate (if provided)
-
Identify the appropriate handler, or log an error if there is no registered handler for the type of data provided.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/batsd/receiver.rb', line 32 def receive_data(msg) msg.split("\n").each do |row| puts "received #{row}" if ENV["VVERBOSE"] key, value, type, sample = row.split(/\||:|!/) if handler = Batsd::Receiver.handlers[type.strip.to_sym] handler.handle(key, value, sample) else puts "No handler for type #{type}" end end rescue Exception => e puts "#{Time.now}: Uncaught error #{e.message}" end |