class Fluent::RedisMultiTypeCounterOutput::Pattern
Attributes
count_value[R]
count_value_key[R]
matches[R]
store_list[R]
Public Class Methods
new(conf_element)
click to toggle source
# File lib/fluent/plugin/out_redis_multi_type_counter.rb, line 152 def initialize(conf_element) if !conf_element.has_key?('count_key') && !conf_element.has_key?('count_key_format') raise RedisMultiTypeCounterException, '"count_key" or "count_key_format" is required.' end if conf_element.has_key?('count_key') && conf_element.has_key?('count_key_format') raise RedisMultiTypeCounterException, 'both "count_key" and "count_key_format" are specified.' end if conf_element.has_key?('count_key') @count_key = conf_element['count_key'] else if conf_element.has_key?('localtime') && conf_element.has_key?('utc') raise RedisMultiTypeCounterException, 'both "localtime" and "utc" are specified.' end is_localtime = true if conf_element.has_key?('utc') is_localtime = false end @count_key_format = [conf_element['count_key_format'], is_localtime] @record_formatter_for_count_key = RecordValueFormatter.new(@count_key_format[0]) end @store_list = false if conf_element.has_key?('store_list') && conf_element['store_list'].downcase == 'true' @store_list = true end if @store_list && (conf_element.has_key?('count_hash_key_format') || conf_element.has_key?('count_zset_key_format')) raise RedisMultiTypeCounterException, 'store_list is true, it should be normal type, not hash or zset' end if conf_element.has_key?('count_hash_key_format') && conf_element.has_key?('count_zset_key_format') raise RedisMultiTypeCounterException, 'both "count_hash_key_format" "count_zset_key_format" are specified.' end if conf_element.has_key?('count_hash_key_format') @count_hash_key_format = conf_element['count_hash_key_format'] @record_formatter_for_count_hash_key = RecordValueFormatter.new(@count_hash_key_format) else @count_hash_key_format = nil end if conf_element.has_key?('count_zset_key_format') @count_zset_key_format = conf_element['count_zset_key_format'] @record_formatter_for_count_zset_key = RecordValueFormatter.new(@count_zset_key_format) else @count_zset_key_format = nil end if conf_element.has_key?('count_value_key') @count_value_key = conf_element['count_value_key'] else @count_value = 1 if conf_element.has_key?('count_value') begin @count_value = Integer(conf_element['count_value']) rescue raise RedisMultiTypeCounterException, 'invalid "count_value", integer required.' end end end @matches = {} conf_element.each_pair.select { |key, value| key =~ /^match_/ }.each { |key, value| name = key['match_'.size .. key.size] @matches[name] = Regexp.new(value) } end
Public Instance Methods
get_count_hash_key(record)
click to toggle source
# File lib/fluent/plugin/out_redis_multi_type_counter.rb, line 243 def get_count_hash_key(record) if @count_hash_key_format == nil return nil else return @record_formatter_for_count_hash_key.key(record) end end
get_count_key(time, record)
click to toggle source
# File lib/fluent/plugin/out_redis_multi_type_counter.rb, line 233 def get_count_key(time, record) if @count_key_format == nil @count_key else count_key = @record_formatter_for_count_key.key(record) formatter = TimeFormatter.new(count_key, @count_key_format[1]) formatter.format(time) end end
get_count_value(record)
click to toggle source
# File lib/fluent/plugin/out_redis_multi_type_counter.rb, line 259 def get_count_value(record) if @count_value_key ret = record[@count_value_key] || 0 return ret.kind_of?(Integer) ? ret : 0 else if @count_value return @count_value end end end
get_count_zset_key(record)
click to toggle source
# File lib/fluent/plugin/out_redis_multi_type_counter.rb, line 251 def get_count_zset_key(record) if @count_zset_key_format == nil return nil else return @record_formatter_for_count_zset_key.key(record) end end
is_match?(record)
click to toggle source
# File lib/fluent/plugin/out_redis_multi_type_counter.rb, line 224 def is_match?(record) @matches.each_pair{ |key, value| if !record.has_key?(key) || !(record[key] =~ value) return false end } return true end