anschel 0.2.0 → 0.3.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: b20f566992eecc30983efa61d5a3154da257061b
4
- data.tar.gz: 64fcbee6db3ccb50472b4ab545ab56e06279a624
3
+ metadata.gz: 6effb5e9164bcf730b5bab24484ad5af1259021b
4
+ data.tar.gz: 1ba0f0a949a64850aa81eb80ed6852eb896fb824
5
5
  SHA512:
6
- metadata.gz: e83e46bef67b3dc054aef46e7cd5f3e615508b2bf142f770b243393039c410110994a95a239d20b8a4bef51e68cd5aefbef052e1c0459b2a9e15e265052ecdef
7
- data.tar.gz: e809c1bb0881fb6717ccacea4b76981debeb53371a82b0aa20043040fec3b632049ccab763de15b8ffebf0830e772eac37e9094df437da9b829a16d00b3a34b9
6
+ metadata.gz: 461945890b911f2d2d1f4a341c0d76d6d38eb484614f01ed4195d7cbb173f1309d95024a06d7f03e1709411418a6d9a50b0556850ae6e0e5c9676a39f77a0298
7
+ data.tar.gz: 541b50a3e3cb82fed6d195b5efbaf2d366bfb8c74bf5f5240eaad548ff09d5a4b4028be56b354d0ff63f9152f232f46cf6546e311f6402dc6b4159143e10a623
data/Readme.md CHANGED
@@ -11,13 +11,13 @@ Logstash-like for moving events from Kafka into Elasticsearch.
11
11
  Download the jarfile from the [GitHub releases page](https://github.com/sczizzo/anschel/releases)
12
12
  and run like so:
13
13
 
14
- $ java -jar anschel-1.2.3.jar
14
+ $ java -jar anschel-x.y.z.jar
15
15
 
16
16
  ### Usage
17
17
 
18
18
  Just call for help!
19
19
 
20
- $ java -jar anschel-1.2.3.jar help
20
+ $ java -jar anschel-x.y.z.jar help
21
21
  Commands:
22
22
  anschel agent # Run application
23
23
  anschel art # Show application art
@@ -26,7 +26,7 @@ Just call for help!
26
26
 
27
27
  Probably you're most interested in the `agent` command:
28
28
 
29
- $ java -jar anschel-1.2.3.jar help agent
29
+ $ java -jar anschel-x.y.z.jar help agent
30
30
  Usage:
31
31
  anschel agent
32
32
 
@@ -35,9 +35,9 @@ Probably you're most interested in the `agent` command:
35
35
  # Default: /etc/anschel.json
36
36
  -i, [--stats-interval=N] # Interval for reporting stats (seconds)
37
37
  # Default: 30
38
- -L, [--log=LOG] # Log to file instead of STDOUT
39
- -V, [--debug], [--no-debug] # Enable DEBUG-level logging
40
- -Z, [--trace], [--no-trace] # Enable TRACE-level logging (precedence over DEBUG)
38
+ -l, [--log=LOG] # Log to file instead of STDOUT
39
+ -v, [--debug], [--no-debug] # Enable DEBUG-level logging
40
+ -z, [--trace], [--no-trace] # Enable TRACE-level logging (overrides DEBUG)
41
41
 
42
42
  Run application
43
43
 
@@ -48,10 +48,14 @@ Probably you're most interested in the `agent` command:
48
48
  It's kinda like a JSON version of the Logstash config language:
49
49
 
50
50
  {
51
+ // Anschel requires JRuby, and some libraries log via Log4j
51
52
  "log4j": {
52
53
  "path": "/path/to/anschel4j.log",
53
54
  "pattern": "[%d] %p %m (%c)%n"
54
55
  },
56
+
57
+ // Kafka is the only supported input; see the `jruby-kafka` homepage for
58
+ // more details: https://github.com/joekiller/jruby-kafka
55
59
  "kafka": {
56
60
  "queue_size": 2000,
57
61
  "zk_connect": "localhost:2181",
@@ -76,6 +80,9 @@ It's kinda like a JSON version of the Logstash config language:
76
80
  "consumer_timeout_ms": -1,
77
81
  "consumer_restart_sleep_ms": 0
78
82
  },
83
+
84
+ // There's only one output, Elasticsearch; see the `elasticsearch-ruby`
85
+ // homepage for more: https://github.com/elastic/elasticsearch-ruby
79
86
  "elasticsearch": {
80
87
  "queue_size": 2000,
81
88
  "bulk_size": 200,
@@ -85,31 +92,37 @@ It's kinda like a JSON version of the Logstash config language:
85
92
  "reload_on_failure": true,
86
93
  "sniffer_timeout": 5
87
94
  },
95
+
96
+ // Just like Logstash, Anschel has a notion of filters
88
97
  "filter": {
89
- "type": [
98
+
99
+ // "_before" is a special set of filters executed on every event before
100
+ // the main type-specific filters are applied
101
+ "_before": [
90
102
  {
91
- "scan": {
92
- "field": "message",
93
- "pattern": "[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}",
94
- "target": "guids"
103
+ "gsub": {
104
+ "field": "type",
105
+ "match": "-.*",
106
+ "replace": ""
95
107
  }
96
- },
108
+ }
109
+ ],
110
+
111
+ // Each type is allowed any number of filters; see `lib/anschel/filter`
112
+ // for configuration options and available filters
113
+ "some-type": [
97
114
  {
98
115
  "scan": {
99
- "field": "path",
116
+ "field": "message",
100
117
  "pattern": "[A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}",
101
118
  "target": "guids"
102
119
  }
103
120
  }
104
121
  ],
122
+
123
+ // Any "_after" filters will be applied to all events, like "_before"
124
+ // (but, you know, like after the main filters)
105
125
  "_after": [
106
- {
107
- "gsub": {
108
- "field": "type",
109
- "match": "-.*",
110
- "replace": ""
111
- }
112
- },
113
126
  {
114
127
  "index": {}
115
128
  }
@@ -133,14 +146,14 @@ You might deploy Anschel with Upstart. Here's a minimal config:
133
146
  stop on shutdown
134
147
  respawn
135
148
 
136
- exec java -jar anschel-1.2.3.jar \
149
+ exec java -jar anschel-x.y.z.jar \
137
150
  --config /etc/anschel.json --log /var/log/anschel.log
138
151
 
139
152
 
140
153
 
141
- ### Changelog
154
+ ## Changelog
142
155
 
143
- #### v1.0
156
+ ### v1.0
144
157
 
145
158
  _In devlopment_
146
159
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -13,6 +13,7 @@ module Anschel
13
13
 
14
14
  def initialize config, stats, log
15
15
  log.trace event: 'filter', config: config
16
+ config ||= {} # Allow for nil config
16
17
  @filters = Hash.new { |h,k| h[k] = [] }
17
18
  config.each do |event_type, filter_defns|
18
19
  filter_defns.each do |filter_defn|
@@ -35,6 +36,8 @@ module Anschel
35
36
  end
36
37
 
37
38
 
39
+ private
40
+
38
41
  def filtered event, options
39
42
  if remove_field = options[:remove_field]
40
43
  event.delete remove_field
data/lib/anschel/main.rb CHANGED
@@ -40,7 +40,12 @@ module Anschel
40
40
  default: 30
41
41
  include_common_options
42
42
  def agent
43
- log.info event: 'hello', version: VERSION, options: options.to_hash
43
+ log.info \
44
+ event: 'hello',
45
+ version: VERSION,
46
+ options: options.to_hash,
47
+ num_cpus: num_cpus
48
+
44
49
  config = JrJackson::Json.load File.read(options.config), symbolize_keys: true
45
50
  setup_log4j config[:log4j]
46
51
 
@@ -49,8 +54,8 @@ module Anschel
49
54
  filter = Filter.new config[:filter], stats, log
50
55
  output = Output.new config[:elasticsearch], stats, log
51
56
 
52
- stats.create 'count', 0
53
- stats.get 'count'
57
+ stats.create 'event'
58
+ stats.get 'event'
54
59
 
55
60
  ts = num_cpus.times.map do
56
61
  Thread.new do
@@ -58,7 +63,7 @@ module Anschel
58
63
  event = JrJackson::Json.load \
59
64
  input.shift.message.to_s, symbolize_keys: true
60
65
  output.push filter.apply(event)
61
- stats.inc 'count'
66
+ stats.inc 'event'
62
67
  end
63
68
  end
64
69
  end
@@ -11,20 +11,20 @@ module Anschel
11
11
  COMMON_OPTIONS = {
12
12
  log: {
13
13
  type: :string,
14
- aliases: %w[ -L ],
14
+ aliases: %w[ -l ],
15
15
  desc: 'Log to file instead of STDOUT',
16
16
  default: ENV['ANSCHEL_LOG'] || nil
17
17
  },
18
18
  debug: {
19
19
  type: :boolean,
20
- aliases: %w[ -V ],
20
+ aliases: %w[ -v ],
21
21
  desc: 'Enable DEBUG-level logging',
22
22
  default: ENV['ANSCHEL_DEBUG'] || false
23
23
  },
24
24
  trace: {
25
25
  type: :boolean,
26
- aliases: %w[ -Z ],
27
- desc: 'Enable TRACE-level logging (precedence over DEBUG)',
26
+ aliases: %w[ -z ],
27
+ desc: 'Enable TRACE-level logging (overrides DEBUG)',
28
28
  default: ENV['ANSCHEL_TRACE'] || false
29
29
  }
30
30
  }
@@ -48,6 +48,25 @@ module Anschel
48
48
  @logger
49
49
  end
50
50
 
51
+ # Write out a temporary properties file for Log4j
52
+ def setup_log4j config
53
+ config ||= {}
54
+ path = config.delete(:path) || '/dev/stdout'
55
+ pattern = config.delete(:pattern) || '%p [%d] (%c) %m%n'
56
+ Tempfile.open('anschel_log4j') do |f|
57
+ log4j = %Q|
58
+ log4j.rootLogger=INFO, A1
59
+ log4j.appender.A1=org.apache.log4j.RollingFileAppender
60
+ log4j.appender.A1.File=%s
61
+ log4j.appender.A1.layout=org.apache.log4j.PatternLayout
62
+ log4j.appender.A1.layout.ConversionPattern=%s
63
+ | % [ path, pattern ]
64
+ f.write log4j.gsub(/^\s+/,'')
65
+ f.rewind
66
+ org.apache.log4j.PropertyConfigurator.configure(f.path)
67
+ end
68
+ end
69
+
51
70
  end
52
71
  end
53
72
  end
data/lib/anschel/stats.rb CHANGED
@@ -22,9 +22,11 @@ module Anschel
22
22
  end
23
23
 
24
24
 
25
- def create name, default=nil
25
+ def create name, default=0
26
26
  with_lock do
27
- stats[name] = Hash.new { |h,k| h[k] = default }
27
+ stats[name] = {}
28
+ stats[name].default = default
29
+ stats
28
30
  end
29
31
  end
30
32
 
@@ -72,6 +74,8 @@ module Anschel
72
74
  ready_stats = with_lock do
73
75
  stats.keys.flat_map do |k|
74
76
  v = stats[k].delete(:val)
77
+ v ||= stats[k].default
78
+ stats[k][:val] = stats[k].default
75
79
  [
76
80
  [ k, v ],
77
81
  [ "#{k}_rate", 1.0 * v / @interval ]
data/lib/anschel.rb CHANGED
@@ -1,29 +1,14 @@
1
+ require 'thread'
2
+
3
+ Thread.abort_on_exception = true
4
+
1
5
  # Return the number of CPU cores (should work on Unixy platforms)
2
6
  def num_cpus
3
7
  return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java
4
8
  return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist? '/proc/cpuinfo'
5
9
  return `sysctl -a | grep cpu`.split(/\s+/,2).last.to_i
6
10
  rescue
7
- return 1
11
+ return 2
8
12
  end
9
13
 
10
- def setup_log4j config
11
- path = config.delete(:path) || '/var/log/anschel4j.log'
12
- pattern = config.delete(:pattern) || '[%d] %p %m (%c)%n'
13
- Tempfile.open('anschel_log4j') do |f|
14
- log4j = %Q|
15
- log4j.rootLogger=INFO, A1
16
- log4j.appender.A1=org.apache.log4j.RollingFileAppender
17
- log4j.appender.A1.File=%s
18
- log4j.appender.A1.layout=org.apache.log4j.PatternLayout
19
- log4j.appender.A1.layout.ConversionPattern=%s
20
- | % [ path, pattern ]
21
- f.write log4j.gsub(/^\s+/,'')
22
- f.rewind
23
- org.apache.log4j.PropertyConfigurator.configure(f.path)
24
- end
25
- end
26
-
27
- Thread.abort_on_exception = true
28
-
29
14
  require_relative 'anschel/main'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anschel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer