Class: NewRelic::Agent::EventBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/event_buffer.rb

Direct Known Subclasses

PrioritySampledBuffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capacity) ⇒ EventBuffer

Returns a new instance of EventBuffer.



23
24
25
26
27
# File 'lib/new_relic/agent/event_buffer.rb', line 23

def initialize(capacity)
  @capacity = capacity
  @items = []
  @seen = 0
end

Instance Attribute Details

#capacityObject



21
22
23
# File 'lib/new_relic/agent/event_buffer.rb', line 21

def capacity
  @capacity
end

Instance Method Details

#<<(x) ⇒ Object



48
49
50
51
# File 'lib/new_relic/agent/event_buffer.rb', line 48

def <<(x)
  append(x)
  self # return self for method chaining
end

#append(x) ⇒ Object



43
44
45
46
# File 'lib/new_relic/agent/event_buffer.rb', line 43

def append(x)
  @seen += 1
  append_event(x)
end

#full?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/new_relic/agent/event_buffer.rb', line 53

def full?
  @items.size >= @capacity
end

#metadataObject



81
82
83
84
85
86
87
# File 'lib/new_relic/agent/event_buffer.rb', line 81

def 
  {
    :capacity => @capacity,
    :captured => @items.size,
    :seen => @seen
  }
end

#note_droppedObject



61
62
63
# File 'lib/new_relic/agent/event_buffer.rb', line 61

def note_dropped
  @seen += 1
end

#num_droppedObject



69
70
71
# File 'lib/new_relic/agent/event_buffer.rb', line 69

def num_dropped
  @seen - @items.size
end

#num_seenObject



65
66
67
# File 'lib/new_relic/agent/event_buffer.rb', line 65

def num_seen
  @seen
end

#reset!Object



29
30
31
32
# File 'lib/new_relic/agent/event_buffer.rb', line 29

def reset!
  @items = []
  @seen = 0
end

#sample_rateObject



73
74
75
# File 'lib/new_relic/agent/event_buffer.rb', line 73

def sample_rate
  @seen > 0 ? (size.to_f / @seen) : 0.0
end

#sizeObject



57
58
59
# File 'lib/new_relic/agent/event_buffer.rb', line 57

def size
  @items.size
end

#to_aObject



77
78
79
# File 'lib/new_relic/agent/event_buffer.rb', line 77

def to_a
  @items.dup
end