Class: EventMachine::Nosey::SocketServer
- Inherits:
-
Connection
- Object
- Connection
- EventMachine::Nosey::SocketServer
- Defined in:
- lib/nosey/eventmachine.rb
Constant Summary collapse
- Host =
'/tmp/nosey.socket'
- Port =
nil
- CommandPattern =
/[A-Z]+\n/
Instance Attribute Summary collapse
-
#report ⇒ Object
Returns the value of attribute report.
Class Method Summary collapse
-
.start(report, host = SocketServer::Host, port = SocketServer::Port) ⇒ Object
A nice short-cut for peeps who aren’t familar with EM to fire up an Reporting server with an array of aggregators, host, and a port.
Instance Method Summary collapse
-
#initialize(report) ⇒ SocketServer
constructor
Accept a collection of aggregators that we’ll use to report our stats.
- #process_command(command) ⇒ Object
- #receive_data(data) ⇒ Object
Constructor Details
#initialize(report) ⇒ SocketServer
Accept a collection of aggregators that we’ll use to report our stats.
14 15 16 |
# File 'lib/nosey/eventmachine.rb', line 14 def initialize(report) @report = report end |
Instance Attribute Details
#report ⇒ Object
Returns the value of attribute report.
11 12 13 |
# File 'lib/nosey/eventmachine.rb', line 11 def report @report end |
Class Method Details
.start(report, host = SocketServer::Host, port = SocketServer::Port) ⇒ Object
A nice short-cut for peeps who aren’t familar with EM to fire up an Reporting server with an array of aggregators, host, and a port.
43 44 45 |
# File 'lib/nosey/eventmachine.rb', line 43 def self.start(report, host=SocketServer::Host, port=SocketServer::Port) EventMachine::start_server(host, port, self, report) end |
Instance Method Details
#process_command(command) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nosey/eventmachine.rb', line 27 def process_command(command) case command.strip when 'READ' # This is for more normal uses cases where you want to watch stats send_data report.to_s when 'RESET' # This is used primarly by munin, or other tools that can't track state. send_data report.to_s report.reset when 'QUIT' close_connection_after_writing else send_data "No Comprende. READ, RESET, o QUIT." end end |
#receive_data(data) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/nosey/eventmachine.rb', line 18 def receive_data(data) buffer << data # Look for commands in the buffer and process them # TODO - For higher performance, queue this in a Em::Queue while command = buffer.scan(CommandPattern) process_command command end end |