Skip to content

Commit

Permalink
Merge pull request #2491 from fluent/improve-stats-method
Browse files Browse the repository at this point in the history
Improve stats method
  • Loading branch information
repeatedly authored Jul 11, 2019
2 parents d1ba31a + e252ba4 commit 9f45c70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 16 additions & 4 deletions lib/fluent/plugin/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down

0 comments on commit 9f45c70

Please sign in to comment.