class Fluent::Plugin::FilecountsInput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_filecounts.rb, line 24
def initialize
  super
end

Public Instance Methods

on_timer() click to toggle source
# File lib/fluent/plugin/in_filecounts.rb, line 43
def on_timer
  record = { "query_path" => @path }

  begin

    event_time = Time.now.strftime('%FT%T%:z')
    time_started = Engine.now
    command = "bash -c '\\find #@path -name \".*\" -prune -o -print'"
    files = IO.popen(command)
      .readlines.map(&:chomp)
    time_finished = Engine.now

  rescue StandardError => err
    record["error"] = err.message
  end

  es = MultiEventStream.new

  es.add(Engine.now, { "time" => event_time, "command" => command, "time_to_run" => (time_finished.to_i - time_started.to_i) })
  groups = files.group_by {|e| File.dirname(e) }
  counts = Hash[groups.map{|k,v| [k, v.count]}]
  time = Engine.now
  counts.each {|k,v| es.add(time, Hash[ 'time', event_time, 'path', k, 'count', v ]) }

  router.emit_stream(tag, es)

end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_filecounts.rb, line 71
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_filecounts.rb, line 37
def start
  super

  timer_execute(:filecounts, @interval, &method(:on_timer))
end