Class: Fluent::LatencyOutput
- Inherits:
-
MultiOutput
- Object
- MultiOutput
- Fluent::LatencyOutput
- Defined in:
- lib/fluent/plugin/out_latency.rb
Instance Attribute Summary collapse
-
#latency ⇒ Object
readonly
for test.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
- #flush_emit ⇒ Object
-
#initialize ⇒ LatencyOutput
constructor
A new instance of LatencyOutput.
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ LatencyOutput
Returns a new instance of LatencyOutput.
15 16 17 18 |
# File 'lib/fluent/plugin/out_latency.rb', line 15 def initialize super @latency = [] end |
Instance Attribute Details
#latency ⇒ Object (readonly)
for test
13 14 15 |
# File 'lib/fluent/plugin/out_latency.rb', line 13 def latency @latency end |
Instance Method Details
#configure(conf) ⇒ Object
20 21 22 |
# File 'lib/fluent/plugin/out_latency.rb', line 20 def configure(conf) super end |
#emit(tag, es, chain) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/fluent/plugin/out_latency.rb', line 24 def emit(tag, es, chain) current = Time.now.to_f es.each do |time, record| @latency << (current - time) end chain.next end |
#flush_emit ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/fluent/plugin/out_latency.rb', line 54 def flush_emit latency, @latency = @latency, [] num = latency.size max = num == 0 ? 0 : latency.max avg = num == 0 ? 0 : latency.map(&:to_f).inject(:+) / num.to_f = {"max" => max, "avg" => avg, "num" => num} Engine.emit(@tag, Engine.now, ) end |
#run ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin/out_latency.rb', line 43 def run @last_checked ||= Engine.now while (sleep 0.5) now = Engine.now if now - @last_checked >= @interval flush_emit @last_checked = now end end end |
#shutdown ⇒ Object
37 38 39 40 41 |
# File 'lib/fluent/plugin/out_latency.rb', line 37 def shutdown super @thread.terminate @thread.join end |
#start ⇒ Object
32 33 34 35 |
# File 'lib/fluent/plugin/out_latency.rb', line 32 def start super @thread = Thread.new(&method(:run)) end |