class Fluent::OomKillerOutput

Constants

REGEX1
REGEX2

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_oomkiller.rb, line 6
def configure(conf)
  super
  @logs = {}
  @is_oomlog = false
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_oomkiller.rb, line 20
def emit(tag, es, chain)
  if !@logs[:"#{tag}"].instance_of?(Array)
    @logs[:"#{tag}"] = []
  end
  chain.next
  es.each {|time,record|
    make_record_block(tag, time, record)
  }
end
flush_emit(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_oomkiller.rb, line 67
def flush_emit(tag, time, record)
  @logs[:"#{tag}"].clear
    
  if !@remove_tag_prefix && !@remove_tag_suffix && !@add_tag_prefix && !@add_tag_suffix
    Fluent::Engine.emit(tag, time, record)

  else
    _tag = tag.clone
    filter_record(_tag, time, record)
    if tag != _tag
      Fluent::Engine.emit(_tag, time, record)
    else
      $log.warn "Can not emit message because the tag has not changed. Dropped record #{record}"
    end
  end
  
end
make_record_block(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_oomkiller.rb, line 30
def make_record_block(tag, time, record)
  record.each do |key, value|
    if @is_oomlog then
      @logs[:"#{tag}"] << value
    end
    if /invoked oom-killer:/ =~ value then
      @is_oomlog = true
      @logs[:"#{tag}"] << value
    elsif /Killed process/ =~ value then
      @is_oomlog = false
      parse_record_block(tag, time)
    end
  end
end
parse_record_block(tag, time) click to toggle source
# File lib/fluent/plugin/out_oomkiller.rb, line 47
def parse_record_block(tag, time)
  record = {}
  
  @logs[:"#{tag}"][0] =~ REGEX1
  datetime = Time.parse($1)
  time = datetime.to_i if datetime
  
  @logs[:"#{tag}"][-1] =~ REGEX2
  record['pid'] = $1.to_i
  record['uid'] = $2.to_i
  record['name'] = $3
  record['total_vm_kb'] = $4.to_i
  record['anon_rss_kb'] = $5.to_i
  record['file_rss_kb'] = $6.to_i
  
  record['raw'] = @logs[:"#{tag}"].map {|m| m.strip}.join("\n")
  
  flush_emit(tag, time, record)
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_oomkiller.rb, line 16
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_oomkiller.rb, line 12
def start
  super
end