class NewRelic::Agent::PrioritySampledBuffer
Constants
- PRIORITY_KEY
Attributes
captured_lifetime[R]
seen_lifetime[R]
Public Class Methods
new(capacity)
click to toggle source
Calls superclass method
NewRelic::Agent::EventBuffer::new
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 15 def initialize(capacity) super @captured_lifetime = 0 @seen_lifetime = 0 end
Public Instance Methods
append(priority: nil, event: nil) { || ... }
click to toggle source
expects priority and a block, or an event as a hash with a ‘priority` key.
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 28 def append(priority: nil, event: nil, &blk) increment_seen return if @capacity == 0 if full? priority ||= priority_for(event) if priority_for(@items[0]) < priority heapify_items_array incoming = event || yield @items[0] = incoming @items.fix(0) incoming end else @items << (event || yield) @captured_lifetime += 1 @items[-1] end end
Also aliased as: append_event
capacity=(new_capacity)
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 51 def capacity=(new_capacity) @capacity = new_capacity old_items = @items.to_a old_seen = @seen reset! old_items.each { |i| append(event: i) } @seen = old_seen end
decrement_lifetime_counts_by(n)
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 64 def decrement_lifetime_counts_by(n) @captured_lifetime -= n @seen_lifetime -= n end
heapify_items_array()
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 21 def heapify_items_array if @items.is_a?(Array) @items = Heap.new(@items) { |x| priority_for(x) } end end
metadata()
click to toggle source
Calls superclass method
NewRelic::Agent::EventBuffer#metadata
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 73 def metadata super.merge!( :captured_lifetime => @captured_lifetime, :seen_lifetime => @seen_lifetime ) end
sample_rate_lifetime()
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 69 def sample_rate_lifetime @captured_lifetime > 0 ? (@captured_lifetime.to_f / @seen_lifetime) : 0.0 end
to_a()
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 60 def to_a @items.to_a.dup end
Private Instance Methods
increment_seen()
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 82 def increment_seen @seen += 1 @seen_lifetime += 1 end
priority_for(event)
click to toggle source
# File lib/new_relic/agent/priority_sampled_buffer.rb, line 87 def priority_for(event) event[0][PRIORITY_KEY] end