Class: Statsd::Batch
- Extended by:
- Forwardable
- Defined in:
- lib/statsd.rb
Overview
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 and namespace 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_byte_size ⇒ Object
Returns the value of attribute batch_byte_size.
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
Attributes inherited from Statsd
#delimiter, #host, #namespace, #port, #postfix, #prefix, #stat_delimiter
Instance Method Summary collapse
-
#easy {|Batch| ... } ⇒ 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.
Methods inherited from Statsd
#batch, #connect, #count, #decrement, #gauge, #increment, #set, #time, #timing
Constructor Details
#initialize(statsd) ⇒ Batch
Returns a new instance of Batch.
61 62 63 64 65 66 67 68 69 |
# File 'lib/statsd.rb', line 61 def initialize(statsd) @statsd = statsd @batch_size = statsd.batch_size @batch_byte_size = statsd.batch_byte_size @flush_interval = statsd.flush_interval @backlog = [] @backlog_bytesize = 0 @last_flush = Time.now end |
Instance Attribute Details
#batch_byte_size ⇒ Object
Returns the value of attribute batch_byte_size.
58 59 60 |
# File 'lib/statsd.rb', line 58 def batch_byte_size @batch_byte_size end |
#batch_size ⇒ Object
Returns the value of attribute batch_size.
58 59 60 |
# File 'lib/statsd.rb', line 58 def batch_size @batch_size end |
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
58 59 60 |
# File 'lib/statsd.rb', line 58 def flush_interval @flush_interval end |
Instance Method Details
#easy {|Batch| ... } ⇒ 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.
76 77 78 79 80 |
# File 'lib/statsd.rb', line 76 def easy yield self ensure flush end |
#flush ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/statsd.rb', line 82 def flush unless @backlog.empty? @statsd.send_to_socket @backlog.join("\n") @backlog.clear @backlog_bytesize = 0 @last_flush = Time.now end end |