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.
20 21 22 23 |
# File 'lib/fluent/plugin/out_latency.rb', line 20 def initialize super @latency = [] end |
Instance Attribute Details
#latency ⇒ Object (readonly)
for test
18 19 20 |
# File 'lib/fluent/plugin/out_latency.rb', line 18 def latency @latency end |
Instance Method Details
#configure(conf) ⇒ Object
25 26 27 |
# File 'lib/fluent/plugin/out_latency.rb', line 25 def configure(conf) super end |
#emit(tag, es, chain) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/fluent/plugin/out_latency.rb', line 29 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
59 60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin/out_latency.rb', line 59 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} router.emit(@tag, Engine.now, ) end |
#run ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fluent/plugin/out_latency.rb', line 48 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
42 43 44 45 46 |
# File 'lib/fluent/plugin/out_latency.rb', line 42 def shutdown super @thread.terminate @thread.join end |
#start ⇒ Object
37 38 39 40 |
# File 'lib/fluent/plugin/out_latency.rb', line 37 def start super @thread = Thread.new(&method(:run)) end |