Class: FWC::Raw

Inherits:
Object
  • Object
show all
Defined in:
lib/fwc.rb

Instance Method Summary collapse

Constructor Details

#initialize(matcher, opts = {}) ⇒ Raw

Returns a new instance of Raw.



152
153
154
155
156
157
158
159
# 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

Instance Method Details

#receive(data) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# 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!Object



161
162
163
164
165
166
167
168
169
170
# 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