Class: Fluent::Plugin::FilecountsInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_filecounts.rb

Instance Method Summary collapse

Constructor Details

#initializeFilecountsInput

Returns a new instance of FilecountsInput.



24
25
26
# File 'lib/fluent/plugin/in_filecounts.rb', line 24

def initialize
  super
end

Instance Method Details

#on_timerObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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

#shutdownObject



71
72
73
# File 'lib/fluent/plugin/in_filecounts.rb', line 71

def shutdown
  super
end

#startObject



37
38
39
40
41
# File 'lib/fluent/plugin/in_filecounts.rb', line 37

def start
  super

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