Class: Kurchatov::Riemann::Client
- Inherits:
-
Object
- Object
- Kurchatov::Riemann::Client
- Defined in:
- lib/kurchatov/riemann/client.rb
Constant Summary collapse
- CONNECT_TIMEOUT =
5- SEND_TIMEOUT =
5- RIEMANN_PORT =
5555
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #<<(events) ⇒ Object
- #connect ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #with_connection ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
15 16 17 18 19 |
# File 'lib/kurchatov/riemann/client.rb', line 15 def initialize(opts = {}) @host = opts[:host] @port = opts[:port] || RIEMANN_PORT @mutex = Mutex.new end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/kurchatov/riemann/client.rb', line 9 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/kurchatov/riemann/client.rb', line 9 def port @port end |
Instance Method Details
#<<(events) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kurchatov/riemann/client.rb', line 21 def <<(events) events = events.map { |e| Event.new(e) } = Message.new(:events => events) with_connection do |socket| x = .encode_with_length Timeout::timeout(SEND_TIMEOUT) { socket.write(x) socket.flush } end end |
#connect ⇒ Object
39 40 41 42 43 |
# File 'lib/kurchatov/riemann/client.rb', line 39 def connect Timeout::timeout(CONNECT_TIMEOUT) { @socket ||= TCPSocket.new(@host, @port) } end |
#with_connection ⇒ Object
33 34 35 36 37 |
# File 'lib/kurchatov/riemann/client.rb', line 33 def with_connection @mutex.synchronize do yield(@socket || connect) end end |