Class: Anschel::Main

Inherits:
Mjolnir
  • Object
show all
Defined in:
lib/anschel/main.rb

Constant Summary

Constants inherited from Mjolnir

Anschel::Mjolnir::COMMON_OPTIONS

Instance Method Summary collapse

Methods inherited from Mjolnir

include_common_options

Instance Method Details

#agentObject



38
39
40
41
42
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/anschel/main.rb', line 38

def agent
  log.info \
    event: 'hello',
    version: VERSION,
    options: options.to_hash,
    num_cpus: num_cpus

  input, filter, output, store, stats, ts = \
    nil, nil, nil, nil, nil, nil, nil

  begin
    # Allow for //-style inline comments in JSON
    raw_config = File.read(options.config).gsub(/^\s*\/\/ .*/, '')

    config = JrJackson::Json.load \
      raw_config, symbolize_keys: true

    setup_log4j config[:log4j]

    store  = Store.new config[:store], log

    stats  = Stats.new config[:stats_interval], log

    filter = Filter.new config[:filter], stats, log

    output = Output.new config[:output], stats, log

    input  = Input.new \
      config[:input], config[:queue_size], stats, log, store[:input]

    stats.create 'event'
    stats.get 'event'

    ts = num_cpus.times.map do
      Thread.new do
        loop do
          event = JrJackson::Json.load \
            input.shift, symbolize_keys: true
          output.push filter.apply(event)
          stats.inc 'event'
        end
      end
    end

    ts.each { |t| t.abort_on_exception = true }

  rescue Exception => e
    log.fatal \
      event: 'exception',
      exception: e.inspect,
      class: e.class,
      message: e.message,
      backtrace: e.backtrace
    bye output, input, store, log, :error
    exit 2
  end

  log.info event: 'all-systems-clear'

  trap('SIGINT') do
    bye output, input, store, log
    exit
  end

  ts.map &:join
end

#artObject



26
27
28
# File 'lib/anschel/main.rb', line 26

def art
  puts "\n%s\n" % ART
end

#versionObject



20
21
22
# File 'lib/anschel/main.rb', line 20

def version
  puts VERSION
end