Class: Lookout::Batch
- Inherits:
-
StatsdClient
- Object
- StatsdClient
- Lookout::Batch
- Defined in:
- lib/lookout/statsd.rb
Overview
Some more unabashed borrowing: github.com/reinh/statsd/blob/master/lib/statsd.rb#L410 The big difference between this implementation and reinh’s is that we don’t support namespaces, and we have a bunch of hacks for introducing prefixes to the namespaces we’re acting against.
Batch: A batching statsd proxy
Batch is a subclass of Statsd, but with a constructor that proxies to a normal Statsd instance. It has it’s own batch_size parameters (that inherit defaults from the supplied Statsd instance). It is recommended that some care is taken if setting very large batch sizes. If the batch size exceeds the allowed packet size for UDP on your network, communication troubles may occur and data will be lost.
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
Attributes inherited from StatsdClient
#host, #port, #prefix, #resolve_always
Instance Method Summary collapse
-
#easy ⇒ Object
A convenience method to ensure that data is not lost in the event of an exception being thrown.
- #flush ⇒ Object
-
#initialize(statsd) ⇒ Batch
constructor
A new instance of Batch.
- #send_batch_data(message) ⇒ Object
- #send_method ⇒ Object
Methods inherited from StatsdClient
#batch, #decrement, #gauge, #host_ip_addr, #increment, #send_data, #time, #timing, #update_counter
Constructor Details
#initialize(statsd) ⇒ Batch
Returns a new instance of Batch.
222 223 224 225 226 227 228 229 230 |
# File 'lib/lookout/statsd.rb', line 222 def initialize(statsd) @statsd = statsd @batch_size = statsd.batch_size @backlog = [] @send_data = send_method @host = statsd.host @port = statsd.port @prefix = statsd.prefix end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
219 220 221 |
# File 'lib/lookout/statsd.rb', line 219 def batch_size @batch_size end |
Instance Method Details
#easy ⇒ Object
A convenience method to ensure that data is not lost in the event of an exception being thrown. Batches will be transmitted on the parent socket as soon as the batch is full, and when the block finishes.
237 238 239 240 241 |
# File 'lib/lookout/statsd.rb', line 237 def easy yield self ensure flush end |
#flush ⇒ Object
243 244 245 246 247 248 |
# File 'lib/lookout/statsd.rb', line 243 def flush unless @backlog.empty? @statsd.send_data @backlog.join("\n") @backlog.clear end end |
#send_batch_data(message) ⇒ Object
250 251 252 253 254 255 |
# File 'lib/lookout/statsd.rb', line 250 def send_batch_data() @backlog << if @backlog.size >= @batch_size flush end end |
#send_method ⇒ Object
257 258 259 260 261 262 263 264 |
# File 'lib/lookout/statsd.rb', line 257 def send_method lambda { |data| @backlog << data if @backlog.size >= @batch_size flush end } end |