lib/fluent/plugin/out_flowcounter.rb in fluent-plugin-flowcounter-0.1.2 vs lib/fluent/plugin/out_flowcounter.rb in fluent-plugin-flowcounter-0.1.3
- old
+ new
@@ -31,15 +31,15 @@
@removed_length = @removed_prefix_string.length
end
@count_keys = @count_keys.split(',')
@counts = count_initialized
+ @mutex = Mutex.new
end
def start
super
- @counts = count_initialized
start_watch
end
def shutdown
super
@@ -63,11 +63,13 @@
b = 'bytes'
if @aggregate == :tag
c = name + '_count'
b = name + '_bytes'
end
- @counts[c] = (@counts[c] || 0) + counts
- @counts[b] = (@counts[b] || 0) + bytes
+ @mutex.synchronize {
+ @counts[c] = (@counts[c] || 0) + counts
+ @counts[b] = (@counts[b] || 0) + bytes
+ }
end
def generate_output(counts, step)
rates = {}
counts.keys.each {|key|