Class: Fluent::StatsdEventFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_statsd_event.rb

Instance Method Summary collapse

Constructor Details

#initializeStatsdEventFilter



8
9
10
11
12
# File 'lib/fluent/plugin/filter_statsd_event.rb', line 8

def initialize
  super
  require 'statsd'
  require 'json'
end

Instance Method Details

#configure(conf) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fluent/plugin/filter_statsd_event.rb', line 24

def configure(conf)
  super
  @regexps = []
  @grep.each do |regexp|
    begin
      @regexps << Regexp.compile(regexp)
    rescue RegexpError => e
      log.error "Error: invalid regular expression in grep: #{e}"
    end
  end
  @statsd = Statsd.new(@host, @port)
end

#filter(tag, time, record) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fluent/plugin/filter_statsd_event.rb', line 37

def filter(tag, time, record)

  if @record_key.nil?
    message = record.to_json
  else
    if record[@record_key].is_a? String
      message = record[@record_key].to_s
    else
      message = record[@record_key].to_json
    end
  end

  if @regexps.empty?
    post_event(time, tag, message)
  else
    @regexps.each do |regexp|
      if ::Fluent::StringUtil.match_regexp(regexp, message)
        post_event(time, tag, message)
        break
      end
    end
  end


  record
end