anschel 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15b97f83198b492b0420e72d4fda22b9efd3d74b
4
- data.tar.gz: d32f712b0fbc07e0042e02a3ff8a10065a4cef44
3
+ metadata.gz: ff371260654352fa91cbdafe573a0c8529401139
4
+ data.tar.gz: f44e6ba4188c50dd88fa1a4e302ca113b4478bcb
5
5
  SHA512:
6
- metadata.gz: 9e1df69888065cfd1975d9f3a71926f1cba51ec45ba6c70a44e83029c2b9dd76d14bf51fd09ef357773910242af9583abed06b9fe4c5cbc01a52a43900c523d0
7
- data.tar.gz: 0cc62d605f60a0b0eefaf52b5557d81d2c1ea81de64ed57baff3dd6636a9bbb2dc07d4dc2eca9b043e3b4ff859e6981ad8f9de94b7e038e06d308b72a08ec2de
6
+ metadata.gz: 3f0e10d1ad31dc874ff2d17fdfda0113c4f7f4f53dbf2bdcdffa50e68ddbb61e6fc0ecea4f7c769b97e24e507dc3a69c4b5934f6b3f747eb517d9bb950344759
7
+ data.tar.gz: 91293634f99cb7691dbb2dbec18f130d537167a9cd946b45cce78c1a1784d3aefc46406613d1e0dfb43cc2462c0cb58ff1224cf84e01cc6e467c9d34e4a43cd0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
data/lib/anschel/main.rb CHANGED
@@ -52,7 +52,12 @@ module Anschel
52
52
  stats = Stats.new log, options.stats_interval
53
53
  input = Input.new config[:kafka], stats, log
54
54
  filter = Filter.new config[:filter], stats, log
55
- output = Output.new config[:elasticsearch], stats, log
55
+
56
+ output = if config[:device]
57
+ Output::Device.new config[:device], stats, log
58
+ else
59
+ Output::Elasticsearch.new config[:elasticsearch], stats, log
60
+ end
56
61
 
57
62
  stats.create 'event'
58
63
  stats.get 'event'
@@ -0,0 +1,27 @@
1
+ require 'thread'
2
+
3
+ module Anschel
4
+ module Output
5
+ class Device
6
+ def initialize config, stats, log
7
+ log.trace event: 'output', kind: 'device', config: config
8
+
9
+ path = config.delete(:path)
10
+ qsize = config.delete(:queue_size) || 2000
11
+ @q = SizedQueue.new qsize
12
+
13
+ Thread.new do
14
+ File.open(path, 'w') do |f|
15
+ loop do
16
+ f.puts @q.shift
17
+ end
18
+ end
19
+ end
20
+
21
+ log.info event: 'output-loaded'
22
+ end
23
+
24
+ def push event ; @q.push event end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,53 @@
1
+ require 'thread'
2
+
3
+ require 'typhoeus/adapters/faraday'
4
+ require 'typhoeus'
5
+ require 'elasticsearch'
6
+
7
+
8
+ module Anschel
9
+ module Output
10
+ class Elasticsearch
11
+ def initialize config, stats, log
12
+ log.trace event: 'output', kind: 'elasticsearch', config: config
13
+ pattern = config.delete(:index_pattern)
14
+ qsize = config.delete(:queue_size) || 2000
15
+ bsize = config.delete(:bulk_size) || 500
16
+ timeout = config.delete(:bulk_timeout) || 0.5
17
+ slice = timeout / bsize
18
+ client = Elasticsearch::Client.new config
19
+ client.transport.reload_connections!
20
+
21
+ @queue = SizedQueue.new qsize
22
+
23
+ Thread.new do
24
+ loop do
25
+ events = []
26
+ count = 0
27
+ start = Time.now.to_f
28
+ until (Time.now.to_f - start > timeout) || ((count += 1) > bsize)
29
+ begin
30
+ events.push @queue.shift(true)
31
+ rescue # shift returned immediately
32
+ sleep slice
33
+ end
34
+ end
35
+
36
+ next if events.empty?
37
+
38
+ body = events.map do |e|
39
+ index = e.delete(:_index) || 'logs-anschel'
40
+ { index: { _index: index, _type: e[:type], data: e } }
41
+ end
42
+
43
+ client.bulk body: body
44
+ end
45
+ end
46
+
47
+ log.info event: 'output-loaded'
48
+ end
49
+
50
+ def push event ; @queue.push event end
51
+ end
52
+ end
53
+ end
@@ -1,51 +1,2 @@
1
- require 'thread'
2
-
3
- require 'typhoeus/adapters/faraday'
4
- require 'typhoeus'
5
- require 'elasticsearch'
6
-
7
-
8
- module Anschel
9
- class Output
10
- def initialize config, stats, log
11
- log.trace event: 'output', config: config
12
- pattern = config.delete(:index_pattern)
13
- qsize = config.delete(:queue_size) || 2000
14
- bsize = config.delete(:bulk_size) || 500
15
- timeout = config.delete(:bulk_timeout) || 0.5
16
- slice = timeout / bsize
17
- client = Elasticsearch::Client.new config
18
- client.transport.reload_connections!
19
-
20
- @queue = SizedQueue.new qsize
21
-
22
- Thread.new do
23
- loop do
24
- events = []
25
- count = 0
26
- start = Time.now.to_f
27
- until (Time.now.to_f - start > timeout) || ((count += 1) > bsize)
28
- begin
29
- events.push @queue.shift(true)
30
- rescue # shift returned immediately
31
- sleep slice
32
- end
33
- end
34
-
35
- next if events.empty?
36
-
37
- body = events.map do |e|
38
- index = e.delete(:_index) || 'logs-anschel'
39
- { index: { _index: index, _type: e[:type], data: e } }
40
- end
41
-
42
- client.bulk body: body
43
- end
44
- end
45
-
46
- log.info event: 'output-loaded'
47
- end
48
-
49
- def push event ; @queue.push event end
50
- end
51
- end
1
+ require_relative 'output/elasticsearch'
2
+ require_relative 'output/device'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anschel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +118,8 @@ files:
118
118
  - lib/anschel/metadata.rb
119
119
  - lib/anschel/mjolnir.rb
120
120
  - lib/anschel/output.rb
121
+ - lib/anschel/output/device.rb
122
+ - lib/anschel/output/elasticsearch.rb
121
123
  - lib/anschel/stats.rb
122
124
  homepage: https://github.com/sczizzo/anschel
123
125
  licenses: