diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index 12b5db6e46..fbf3559436 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -741,15 +741,27 @@ def write_step_by_step(metadata, data, format, splits_count, &block) retry end + STATS_KEYS = [ + 'stage_length', + 'stage_byte_size', + 'queue_length', + 'queue_byte_size', + 'available_buffer_space_ratios', + 'total_queued_size', + 'oldest_timekey', + 'newest_timekey' + ] + def statistics - buffer_space = 1.0 - ((@stage_size + @queue_size * 1.0) / @total_limit_size).round + stage_size, queue_size = @stage_size, @queue_size + buffer_space = 1.0 - ((stage_size + queue_size * 1.0) / @total_limit_size).round stats = { 'stage_length' => @stage.size, - 'stage_byte_size' => @stage_size, + 'stage_byte_size' => stage_size, 'queue_length' => @queue.size, - 'queue_byte_size' => @queue_size, + 'queue_byte_size' => queue_size, 'available_buffer_space_ratios' => buffer_space * 100, - 'total_queued_size' => @stage_size + @queue_size, + 'total_queued_size' => stage_size + queue_size, } if (m = timekeys.min) diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index a919cf8cb8..be44e3990b 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -16,6 +16,7 @@ require 'fluent/error' require 'fluent/plugin/base' +require 'fluent/plugin/buffer' require 'fluent/plugin_helper/record_accessor' require 'fluent/log' require 'fluent/plugin_id' @@ -1466,6 +1467,11 @@ def flush_thread_run(state) end end + BUFFER_STATS_KEYS = {} + Fluent::Plugin::Buffer::STATS_KEYS.each { |key| + BUFFER_STATS_KEYS[key] = "buffer_#{key}" + } + def statistics stats = { 'emit_records' => @emit_records, @@ -1481,7 +1487,7 @@ def statistics if @buffer && @buffer.respond_to?(:statistics) (@buffer.statistics['buffer'] || {}).each do |k, v| - stats["buffer_#{k}"] = v + stats[BUFFER_STATS_KEYS[k]] = v end end