Class: Sensu::Extension::Endpoint
- Inherits:
-
Object
- Object
- Sensu::Extension::Endpoint
- Defined in:
- lib/sensu/extensions/graphite.rb
Overview
EndPoint An endpoint is a backend metric store. This is a compositional object to help keep the rest of the code sane.
Constant Summary collapse
- MAX_QUEUE_SIZE =
EM::Connection.send_data batches network connection writes in 16KB We should start out by having all data in the queue flush in the space of a single loop tick.
2048
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
- #flush_to_net ⇒ Object
-
#initialize(name, host, port) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #queue_length ⇒ Object
- #relay_event(data) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(name, host, port) ⇒ Endpoint
Returns a new instance of Endpoint.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/sensu/extensions/graphite.rb', line 134 def initialize(name, host, port) @queue = [] @connection = EM.connect(host, port, ConnectionHandler) @connection.name = name @connection.host = host @connection.port = port @connection. = @queue EventMachine::PeriodicTimer.new(60) do Sensu::Logger.get.info("Graphite: queue size for #{name}: #{queue_length}") end end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
132 133 134 |
# File 'lib/sensu/extensions/graphite.rb', line 132 def connection @connection end |
#queue ⇒ Object
Returns the value of attribute queue.
132 133 134 |
# File 'lib/sensu/extensions/graphite.rb', line 132 def queue @queue end |
Instance Method Details
#flush_to_net ⇒ Object
152 153 154 155 |
# File 'lib/sensu/extensions/graphite.rb', line 152 def flush_to_net sent = @connection.send_data(@queue.join) @queue = [] if sent > 0 end |
#queue_length ⇒ Object
146 147 148 149 150 |
# File 'lib/sensu/extensions/graphite.rb', line 146 def queue_length @queue .map(&:bytesize) .reduce(:+) || 0 end |
#relay_event(data) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/sensu/extensions/graphite.rb', line 157 def relay_event(data) if @connection.connected @queue << data if queue_length >= MAX_QUEUE_SIZE flush_to_net Sensu::Logger.get.debug('Graphite: successfully flushed to network') end end end |
#stop ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/sensu/extensions/graphite.rb', line 167 def stop if @connection.connected flush_to_net #@connection.close_connection_after_writing @connection.close_connection # Force connection closing, do not wait. end end |