Class: Statsd::Reporter
- Inherits:
-
Object
- Object
- Statsd::Reporter
- Defined in:
- lib/statsd/reporter.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#pool_size ⇒ Object
readonly
Returns the value of attribute pool_size.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#statsd_host ⇒ Object
readonly
Returns the value of attribute statsd_host.
Instance Method Summary collapse
- #enqueue(metric) ⇒ Object
-
#initialize(statsd_host, batch_size, pool_size) ⇒ Reporter
constructor
A new instance of Reporter.
- #spawn_thread_pool ⇒ Object
Constructor Details
#initialize(statsd_host, batch_size, pool_size) ⇒ Reporter
Returns a new instance of Reporter.
9 10 11 12 13 14 15 16 |
# File 'lib/statsd/reporter.rb', line 9 def initialize(statsd_host, batch_size, pool_size) @pool_size = pool_size || 1 @statsd_host = statsd_host @messages = [] @queue = Queue.new @batch_size = batch_size @pool_size.times { |i| Thread.new { Thread.current[:id] = i; spawn_thread_pool } } end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
7 8 9 |
# File 'lib/statsd/reporter.rb', line 7 def batch_size @batch_size end |
#messages ⇒ Object
Returns the value of attribute messages.
6 7 8 |
# File 'lib/statsd/reporter.rb', line 6 def @messages end |
#pool_size ⇒ Object (readonly)
Returns the value of attribute pool_size.
7 8 9 |
# File 'lib/statsd/reporter.rb', line 7 def pool_size @pool_size end |
#queue ⇒ Object
Returns the value of attribute queue.
6 7 8 |
# File 'lib/statsd/reporter.rb', line 6 def queue @queue end |
#statsd_host ⇒ Object (readonly)
Returns the value of attribute statsd_host.
7 8 9 |
# File 'lib/statsd/reporter.rb', line 7 def statsd_host @statsd_host end |
Instance Method Details
#enqueue(metric) ⇒ Object
32 33 34 |
# File 'lib/statsd/reporter.rb', line 32 def enqueue(metric) queue << metric end |
#spawn_thread_pool ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/statsd/reporter.rb', line 18 def spawn_thread_pool loop do if queue.size >= batch_size begin while << queue.pop(true) flush end rescue ThreadError flush #flush pending queue messages end end end end |