lib/fluent/plugin/out_groupcounter.rb in fluent-plugin-groupcounter-0.2.0 vs lib/fluent/plugin/out_groupcounter.rb in fluent-plugin-groupcounter-0.2.1
- old
+ new
@@ -1,8 +1,10 @@
class Fluent::GroupCounterOutput < Fluent::Output
Fluent::Plugin.register_output('groupcounter', self)
+ PATTERN_MAX_NUM = 20
+
def initialize
super
require 'pathname'
end
@@ -22,10 +24,11 @@
config_param :count_suffix, :string, :default => '_count'
config_param :max_suffix, :string, :default => '_max'
config_param :min_suffix, :string, :default => '_min'
config_param :avg_suffix, :string, :default => '_avg'
config_param :store_file, :string, :default => nil
+ (1..PATTERN_MAX_NUM).each {|i| config_param "pattern#{i}".to_sym, :string, :default => nil }
attr_accessor :count_interval
attr_accessor :counts
attr_accessor :saved_duration
attr_accessor :saved_at
@@ -67,10 +70,18 @@
@removed_length = @removed_prefix_string.length
end
@group_by_keys = @group_by_keys.split(',') if @group_by_keys
+ @pattern = {}
+ (1..PATTERN_MAX_NUM).each do |i|
+ next unless conf["pattern#{i}"]
+ replace, regexp = conf["pattern#{i}"].split(/ +/, 2)
+ raise Fluent::ConfigError, "pattern#{i} does not contain 2 parameters" unless regexp
+ @pattern[replace] = Regexp.compile(regexp)
+ end
+
if @store_file
f = Pathname.new(@store_file)
if (f.exist? && !f.writable_real?) || (!f.exist? && !f.parent.writable_real?)
raise Fluent::ConfigError, "#{@store_file} is not writable"
end
@@ -229,9 +240,12 @@
else # @group_by_keys
values = @group_by_keys.map {|key| record[key] || 'undef'}
group_key = values.join(@delimiter)
end
group_key = group_key.to_s.force_encoding('ASCII-8BIT')
+
+ @pattern.each {|replace, regexp| break if group_key.gsub!(regexp, replace) }
+ group_key
end
def sum(a, b)
a ||= 0
b ||= 0