class FWC::Raw

Public Class Methods

new(matcher, opts={}) click to toggle source
# File lib/fwc.rb, line 152
def initialize matcher, opts={}
  @threshold = opts[:threshold]
  @matcher = matcher
  @count = 0
  @rate = 0
  @disabled = false
  @first = Time.now
end

Public Instance Methods

receive(data) click to toggle source
# File lib/fwc.rb, line 172
def receive data
  return if not @matcher.matches? data

  if not @tags.nil? and not (@tags & (d["tags"] || [])).empty?
    return
  end

  if not @disabled and @count > 100
    diff = (Time.now - @first)
    rate = (@count / diff)

    if rate > @threshold
      r = rate.to_i
      desc = "#{r}/s > #{@threshold}/s"
      FWC.log.info "Raw: disabled - rate too high (#{desc})"
      @disabled = true
    end
  end

  unless @disabled
    FWC.log.info "#{@count}: #{data}"
  end

  @count += 1
end
report!() click to toggle source
# File lib/fwc.rb, line 161
def report!
  return if @count == 0

  FWC.log.info "Raw Report:"
  FWC.log.info "  count: #{@count}"

  @first = Time.now
  @count = 0
  @disabled = false
end