Skip to content

Commit

Permalink
add comment option
Browse files Browse the repository at this point in the history
  • Loading branch information
sonots committed Jan 14, 2014
1 parent a820932 commit ba10380
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ This plugin does not emit, just writes into the log file as

One of num/byte. Default: num

- comment

Just a comment. You may use this to mark where you put flowcounter_simple.

## Relatives

There is a [fluent-plugin-flowcounter](https://github.com/tagomoris/fluent-plugin-flowcounter),
Expand Down
10 changes: 9 additions & 1 deletion lib/fluent/plugin/out_flowcounter_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Fluent::FlowCounterSimpleOutput < Fluent::Output

config_param :indicator, :string, :default => 'num'
config_param :unit, :string, :default => 'second'
config_param :comment, :string, :default => nil

attr_accessor :last_checked

Expand Down Expand Up @@ -35,6 +36,13 @@ def configure(conf)
raise RuntimeError, "@unit must be one of second/minute/hour/day"
end

@output_proc =
if @comment
Proc.new {|count| "plugin:out_flowcounter_simple\tcount:#{count}\tindicator:#{@indicator}\tunit:#{@unit}\tcomment:#{@comment}" }
else
Proc.new {|count| "plugin:out_flowcounter_simple\tcount:#{count}\tindicator:#{@indicator}\tunit:#{@unit}" }
end

@count = 0
@mutex = Mutex.new
end
Expand All @@ -59,7 +67,7 @@ def countup(count)
def flush_emit(step)
count, @count = @count, 0
if count > 0
$log.info "plugin:out_flowcounter_simple\tcount:#{count}\tindicator:#{@indicator}\tunit:#{@unit}"
$log.info @output_proc.call(count)
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/plugin/test_out_flowcounter_simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def test_byte
assert( log.include?("count:3360"), log )
end

def test_comment
d1 = create_driver(CONFIG + %[comment foobar], 'test.tag1')
d1.run do
1.times do
d1.emit({'message'=> 'a' * 100})
d1.emit({'message'=> 'b' * 100})
d1.emit({'message'=> 'c' * 100})
end
end
log = capture_log { d1.instance.flush_emit(60) }
assert( log.include?("comment:foobar"), log )
end

private

def capture_log
Expand Down

0 comments on commit ba10380

Please sign in to comment.