-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "em-zeromq" | ||
require "logger" | ||
require "statsdserver/proto/v1" | ||
|
||
class StatsdServer | ||
class Input | ||
class ZeroMQ | ||
attr_accessor :logger, | ||
:stats | ||
|
||
public | ||
def initialize | ||
@logger = Logger.new(STDOUT) | ||
end | ||
|
||
public | ||
def on_readable(socket, parts) | ||
EM.defer do | ||
parts.each do |part| | ||
str = part.copy_out_string | ||
receive_data(str) | ||
end | ||
end | ||
end | ||
|
||
public | ||
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.message) | ||
end | ||
else | ||
@logger.warn("unknown protocol version #{proto_ver} in update #{packet}") | ||
return | ||
end | ||
|
||
end # def receive_data | ||
end # class Ucp | ||
end # class Input | ||
end # class StatsdServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters