lib/fluent/plugin/out_groupcounter.rb in fluent-plugin-groupcounter-0.2.1 vs lib/fluent/plugin/out_groupcounter.rb in fluent-plugin-groupcounter-0.2.2
- old
+ new
@@ -35,14 +35,10 @@
attr_accessor :last_checked
def configure(conf)
super
- if @group_by_keys.nil? and @group_by_expression.nil?
- raise Fluent::ConfigError, "Either of group_by_keys or group_by_expression must be specified"
- end
-
if @count_interval
@count_interval = @count_interval.to_i
else
@count_interval = case @unit
when 'minute' then 60
@@ -112,16 +108,17 @@
def generate_fields(counts_per_tag, output = {}, key_prefix = '')
return {} unless counts_per_tag
# total_count = counts_per_tag.delete('__total_count')
counts_per_tag.each do |group_key, count|
+ group_key_with = group_key.empty? ? "" : group_key + @delimiter
output[key_prefix + group_key + @count_suffix] = count[:count] if count[:count]
- output[key_prefix + group_key + "#{@delimiter}#{@min_key}#{@min_suffix}"] = count[:min] if count[:min]
- output[key_prefix + group_key + "#{@delimiter}#{@max_key}#{@max_suffix}"] = count[:max] if count[:max]
- output[key_prefix + group_key + "#{@delimiter}#{@avg_key}#{@avg_suffix}"] = count[:sum] / (count[:count] * 1.0) if count[:sum] and count[:count] > 0
- # output[key_prefix + group_key + "#{@delimiter}rate"] = ((count[:count] * 100.0) / (1.00 * step)).floor / 100.0
- # output[key_prefix + group_key + "#{@delimiter}percentage"] = count[:count] * 100.0 / (1.00 * total_count) if total_count > 0
+ output[key_prefix + group_key_with + "#{@min_key}#{@min_suffix}"] = count[:min] if count[:min]
+ output[key_prefix + group_key_with + "#{@max_key}#{@max_suffix}"] = count[:max] if count[:max]
+ output[key_prefix + group_key_with + "#{@avg_key}#{@avg_suffix}"] = count[:sum] / (count[:count] * 1.0) if count[:sum] and count[:count] > 0
+ # output[key_prefix + group_key_with + "rate"] = ((count[:count] * 100.0) / (1.00 * step)).floor / 100.0
+ # output[key_prefix + group_key_with + "percentage"] = count[:count] * 100.0 / (1.00 * total_count) if total_count > 0
end
output
end
@@ -137,11 +134,11 @@
else
return generate_fields(counts['all']) if @aggregate == :all
output = {}
counts.keys.each do |tag|
- generate_fields(counts[tag], output, stripped_tag(tag) + '_')
+ generate_fields(counts[tag], output, stripped_tag(tag) + @delimiter)
end
output
end
end
@@ -235,12 +232,14 @@
# Expand record with @group_by_keys, and get a value to be a group_key
def group_key(tag, time, record)
if @group_by_expression
tags = tag.split('.')
group_key = expand_placeholder(@group_by_expression, record, tag, tags, Time.at(time))
- else # @group_by_keys
+ elsif @group_by_keys
values = @group_by_keys.map {|key| record[key] || 'undef'}
group_key = values.join(@delimiter)
+ else
+ return ""
end
group_key = group_key.to_s.force_encoding('ASCII-8BIT')
@pattern.each {|replace, regexp| break if group_key.gsub!(regexp, replace) }
group_key