fluent-plugin-norikra 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5290c7b55ef87189a7ff88bce1f1e490f72ed2cc
4
- data.tar.gz: 0c5dfe962ed60e8fc45baec125237349f78607e7
3
+ metadata.gz: fb3d07d2f2997aa968bdeb9a2c9b367d11b8402d
4
+ data.tar.gz: ba678530347bc93801c557d70eaf5bda2aec33e5
5
5
  SHA512:
6
- metadata.gz: 4596d0b75141328f0ded539b44f1281e4a719786ce848231a261d0f1555710d9d72c589131ab078a15f71fb3d2f8e42d2c4e7aac4a22f91075fcdb49a78df5ea
7
- data.tar.gz: 400f0cf1365c998e7a3c7d81a2ba3f58b9406662ddb4b87b23dda5cff7d4f80b06b92589fa10516b152b930930ef9867b5acbedd46fc3da8a7f6817fed196dbd
6
+ metadata.gz: 06681dafb3386c4773dd557b801103c0d73f9880607d9521abc860b17272b129f612a83217fa305254fa19de569b426e02fa49056fac962525ab9035b1b32ab9
7
+ data.tar.gz: bab9693ba1db4ca31416bde2dc4d6b1ca91b388562c7364d362adf8916902aa509cb5f42f4729f935813f9f1a22882f28d5a77102a954c257ceb53309167f159
data/README.md CHANGED
@@ -1,31 +1,35 @@
1
1
  # fluent-plugin-norikra
2
2
 
3
- Fluentd output plugin to send events to norikra server, and to fetch events (and re-send on fluentd network) from norikra server.
3
+ Fluentd plugins to send/receive events to/from Norikra server.
4
4
 
5
- With NorikraOutput, we can:
5
+ Norikra is an open source server software provides "Stream Processing" with SQL, written in JRuby, runs on JVM, licensed under GPLv2.
6
+ For more details, see: http://norikra.github.io/ .
6
7
 
7
- * execute Norikra server as built-in process dynamically
8
- * generate Norikra's target automatically with Fluentd's tags
9
- * register queries automatically with Fluentd's tags and messages
10
- * get all events on Norikra and emit on Fluentd network automatically
8
+ fluent-plugin-norikra has 3 plugins: in\_norikra, out\_norikra and out\_norikra\_filter.
9
+ * in\_norikra
10
+ * fetch events of query results from Norikra server
11
+ * out\_norikra
12
+ * send events to Norikra server
13
+ * out\_norikra\_filter
14
+ * launch Norikra server as child process dynamically, as needed
15
+ * use Norikra server as event filter (like out\_exec\_filter)
16
+ * register/execute queries for targets newly incoming
11
17
 
12
18
  # Setup
13
19
 
14
- At first, install JRuby and Norikra on your host if you are not using stand-alone Norikra servers.
15
-
16
- 1. install latest jruby
17
- * (rbenv) `rbenv install jruby-1.7.4`
18
- * (rvm) `rvm install jruby-1.7.4`
19
- * or other tools you want.
20
- 2. swith to jruby, and install Norikra
21
- * `gem install norikra`
22
- 3. check and note `jruby` and `norikra-server`
23
- * `which jruby`
24
- * `which norikra-server`
25
- 4. switch CRuby (with Fluentd), and install this plugin
26
- * `gem install fluent-plugin-norikra` (or use `fluent-gem`)
27
- 5. configure Fluentd, and execute.
28
- * and write `path` configuration of `<server>` section (if you want)
20
+ `fluent-plugin-norikra` works with Norikra server, on same server with Fluentd, or anywhere reachable over network from Fluentd.
21
+ For Norikra server setup, see: http://norikra.github.io/ .
22
+
23
+ NOTES:
24
+ * Fluentd and fluent-plugin-norikra requires CRuby (MatzRuby).
25
+ * Norikra requires JRuby.
26
+
27
+ To use out\_norikra\_filter with dynamic Norikra server launching, check actual path of command `norikra` under installed JRuby tree. (ex: `$HOME/.rbenv/versions/jruby-1.7.8/bin/norikra`)
28
+
29
+ To use this plugin:
30
+ 1. run `gem install fluent-plugin-norikra` or `fluent-gem install fluent-plugin-norikra` to install plugin
31
+ 1. edit configuration files
32
+ 1. execute fluentd
29
33
 
30
34
  # Configuration
31
35
 
@@ -33,87 +37,156 @@ For variations, see `example` directory.
33
37
 
34
38
  ## NorikraOutput
35
39
 
36
- With built-in Norikra server, to receive tags like `event.foo` and send norikra's target `foo`, and get count of its records per minute, and per hour.
37
-
38
- <match event.*>
39
- type norikra
40
- norikra localhost:26571 # this is default
41
- <server>
42
- execute yes
43
- jruby /home/user/.rbenv/versions/jruby-1.7.4/bin/jruby
44
- path /home/user/.rbenv/versions/jruby-1.7.4/bin/norikra
45
- opts -Xmx2g
46
- </server>
47
-
48
- remove_tag_prefix event
49
- target_map_tag yes
50
-
51
- <default>
52
- <query>
53
- name count_min_${target}
54
- expression SELECT count(*) AS cnt FROM ${target}.win:time_batch(1 minute)
55
- tag count.min.${target}
56
- </query>
57
- <query>
58
- name count_hour_${target}
59
- expression SELECT count(*) AS cnt FROM ${target}.win:time_batch(1 hour)
60
- tag count.hour.${target}
61
- </query>
62
- </default>
63
- </match>
64
-
65
- With default setting, all fields are defined as 'string', so you must use `cast` for numerical processing in query (For more details, see Norikra and Esper's documents).
66
-
67
- If you know some field's types of records, you can define types of these fields. This plugin will define field types before it send records into Norikra server.
68
-
69
- <match event.*>
70
- type norikra
71
- norikra localhost:26571 # this is default
72
- <server>
73
- execute yes
74
- jruby /home/user/.rbenv/versions/jruby-1.7.4/bin/jruby
75
- path /home/user/.rbenv/versions/jruby-1.7.4/bin/norikra
76
- opts -Xmx2g
77
- </server>
78
-
79
- remove_tag_prefix event
80
- target_map_tag yes
81
-
82
- <default>
83
- field_int amount
84
- field_long size
85
- field_double price
86
-
87
- <query>
88
- name sales_${target}
89
- expression SELECT price * amount AS FROM ${target}.win:time_batch(1 minute) WHERE size > 0
90
- tag sales.min.${target}
91
- </query>
92
- </default>
93
- </match>
94
-
95
- Additional field definitions and query registrations should be written in `<target TARGET_NAME>` sections. In each sections (or also in 'default'), you can specify `auto_field false` to suppress field number which increasing infinitely.
96
-
97
- <default>
98
- ... # for all of access logs
99
- </default>
100
- <target login>
101
- field_string protocol # like 'oauth', 'openid', ...
102
- field_int proto_num # integer means internal id of protocols
103
- <query>
104
- name protocol
105
- expression SELECT protocol, count(*) AS cnt FROM ${target}.win:time_batch(1 hour) WHERE proto_num != 0 GROUP BY protocol
106
- tag login.counts
107
- </query>
108
- </target>
109
- <target other_action>
110
- auto_field false
111
- ...
112
- </target>
113
- # ...
40
+ Sends events to remote Norikra server. Minimal configurations are:
41
+ ```apache
42
+ <match data.*>
43
+ type norikra
44
+ norikra norikra.server.local:26571
45
+
46
+ remove_tag_prefix data
47
+ target_map_tag true # fluentd's tag 'data.event' -> norikra's target 'event'
48
+ </match>
49
+ ```
50
+
51
+ NorikraOutput plugin opens Norikra's target for newly incoming tags. You can specify fields to include/exclude, and specify types of each fields, for each targets (and all targets by `default`). Definitions in `<target TARGET_NAME>` overwrites `<default>` specifications.
52
+ ```apache
53
+ <match data.*>
54
+ type norikra
55
+ norikra norikra.server.local:26571
56
+
57
+ target_map_tag true # fluentd's tag -> norikra's target
58
+ remove_tag_prefix data
59
+ # other options:
60
+ # target_map_key KEY_NAME # use specified key's value as target in fluentd event
61
+ # target_string STRING # use fixed target name specified
62
+
63
+ <default>
64
+ include * # send all fields values to norikra
65
+ exclude time # exclude 'time' field from sending event values
66
+ # AND/OR 'include_regexp' and 'exclude_regexp' available
67
+ field_integer seq # field 'seq' defined as integer for all targets
68
+ </default>
69
+
70
+ <target users>
71
+ field_string name,address
72
+ field_integer age
73
+ field_float height,weight
74
+ field_boolean superuser
75
+ </target>
76
+ </match>
77
+ ```
78
+
79
+ With default setting, all fields are defined as 'string', so you must use `field_xxxx` parameters for numerical processing in query (For more details, see Norikra and Esper's documents).
80
+
81
+ If fluentd's events has so many variations of sets of fields, you can specify not to include fields automatically, with `auto_field` option:
82
+ ```apache
83
+ <match data.*>
84
+ type norikra
85
+ norikra norikra.server.local:26571
86
+
87
+ target_map_tag true # fluentd's tag 'data.event' -> norikra's target 'event'
88
+ remove_tag_prefix data
89
+
90
+ <default>
91
+ auto_field false # norikra includes fields only used in queries.
92
+ </default>
93
+ </match>
94
+ ```
114
95
 
115
96
  Fields which are referred in queries are automatically registered on norikra server in spite of `auto_field false`.
116
97
 
98
+ ** NOTE: <default> and <target> sections in NorikraOutput ignores <query> sections. see NorikraFilterOutput **
99
+
100
+ ## NorikraInput
101
+
102
+ Fetch events from Norikra server, and emits these into Fluentd itself. NorikraInput uses Norikra's API `event` (for queries), and `sweep` (for query groups).
103
+
104
+ Minimal configurations:
105
+ ```apache
106
+ <source>
107
+ type norikra
108
+ norikra norikra.server.local:26571
109
+ <fetch>
110
+ method sweep
111
+ # target QUERY_GROUP_NAME # not specified => default query group
112
+ tag query_name
113
+ tag_prefix norikra.query
114
+ # other options:
115
+ # tag field FIELDNAME : tag by value with specified field name in output event
116
+ # tag string STRING : fixed string specified
117
+ interval 3s # interval to call api
118
+ </fetch>
119
+ </source>
120
+ ```
121
+
122
+ Available `<fetch>` methods are `event` and `sweep`. `target` parameter is handled as query name for `event`, and as query group name for `sweep`.
123
+ ```apache
124
+ <source>
125
+ type norikra
126
+ norikra norikra.server.local:26571
127
+ <fetch>
128
+ method event
129
+ target data_count_1hour
130
+ tag string data.count.1hour
131
+ interval 60m
132
+ </fetch>
133
+ <fetch>
134
+ method event
135
+ target data_count_5min
136
+ tag string data.count.5min
137
+ interval 5m
138
+ </fetch>
139
+ <fetch>
140
+ method sweep
141
+ target count_queries
142
+ tag field target_name
143
+ tag_prefix data.count.all
144
+ interval 15s
145
+ </fetch>
146
+ </source>
147
+ ```
148
+
149
+ ## NorikraFilterOutput
150
+
151
+ NorikraFilterOutput has all features of both of NorikraInput and NorikraOutput, and also has additional features:
152
+ * execute Norikra server
153
+ * runs queries for newly incoming targets.
154
+
155
+ If you runs Norikra as standalone process, better configurations are to use NorikraInput and NorikraOutput separately. NorikraFilterOutput is for simple aggregations and filterings.
156
+
157
+ Configuration example to receive tags like `event.foo` and send norikra's target `foo`, and get count of its records per minute, and per hour with built-in Norikra server:
158
+ ```apache
159
+ <match event.*>
160
+ type norikra_filter
161
+ <server>
162
+ path /home/username/.rbenv/versions/jruby-1.7.4/bin/norikra
163
+ # opts -Xmx2g # options of 'norikra start'
164
+ </server>
165
+
166
+ remove_tag_prefix event
167
+ target_map_tag yes
168
+
169
+ <default>
170
+ <query>
171
+ name count_min_${target}
172
+ group count_query_group # or default when omitted
173
+ expression SELECT count(*) AS cnt FROM ${target}.win:time_batch(1 minute)
174
+ tag count.min.${target}
175
+ </query>
176
+ <query>
177
+ name count_hour_${target}
178
+ group count_query_group
179
+ expression SELECT count(*) AS cnt FROM ${target}.win:time_batch(1 hour)
180
+ tag count.hour.${target}
181
+ </query>
182
+ </default>
183
+ </match>
184
+ ```
185
+
186
+ Results of queries automatically registered by NorikraFilterOutput with `tag` parameter, will be fetched automatically by this plugin, and re-emitted into Fluentd itself.
187
+
188
+ Other all options are available as same as NorikraInput and NorikraOutput. `<default>`, `<target>` and `<fetch>` sections, `auto_field`, `include|exclude` and `field_xxxx` specifiers for targets and parameters for `<fetch>` sections.
189
+
117
190
  ### Input event data filtering
118
191
 
119
192
  If you want send known fields only, specify `exclude *` and `include` or `include_regexp` like this:
@@ -152,34 +225,10 @@ Norikra's target (like table name) can be generated from:
152
225
  * all records are sent in single target
153
226
  * `target_string from_fluentd`
154
227
 
155
- ### Event sweeping
156
-
157
- Norikra server accepts queries and events from everywhere other than Fluentd. This plugin can get events from these queries/events.
158
-
159
- To gather all events of Norikra server, including queries from outside of Fluentd configurations, write `<event>` section.
160
-
161
- <events>
162
- method sweep
163
- tag query_name
164
- # tag field FIELDNAME
165
- # tag string FIXED_STRING
166
- tag_prefix norikra.event # actual tag: norikra.event.QUERYNAME
167
- sweep_interval 5s
168
- </events>
169
-
170
- NOTE: 'sweep' get all events from Norikra, and other clients cannot get these events. Take care for other clients.
171
-
172
- # FAQ
173
-
174
- * TODO: write this section
175
- * `fetch_interval`
176
- * error logs for new target, success logs of retry
177
- * input/output plugin
178
- * output plugin with active-standby servers
179
-
180
228
  # TODO
181
229
 
182
- * TODO: write this section
230
+ * write abou these topics
231
+ * error logs for new target, success logs of retry
183
232
 
184
233
  # Copyright
185
234
 
data/example/blank.conf CHANGED
@@ -3,11 +3,10 @@
3
3
  </source>
4
4
 
5
5
  <match event.*>
6
- type norikra
6
+ type norikra_filter
7
7
  norikra localhost:26571 # this is default
8
8
  <server>
9
- execute yes
10
- path /Users/tagomoris/.rbenv/versions/jruby-1.7.3/bin/norikra
9
+ path /Users/tagomoris/.rbenv/versions/jruby-1.7.8/bin/norikra # $HOME
11
10
  </server>
12
11
 
13
12
  remove_tag_prefix event
data/example/blank.rb ADDED
@@ -0,0 +1,15 @@
1
+ source {
2
+ type "forward"
3
+ }
4
+
5
+ home_dir = ::Object::ENV['HOME']
6
+
7
+ match('event.*') {
8
+ type "norikra_filter"
9
+ norikra "localhost:26571"
10
+ server {
11
+ path "#{home_dir}/.rbenv/versions/jruby-1.7.8/bin/norikra"
12
+ }
13
+ remove_tag_prefix "event"
14
+ target_map_tag true
15
+ }
data/example/blank2.conf CHANGED
@@ -3,7 +3,7 @@
3
3
  </source>
4
4
 
5
5
  <match event.*>
6
- type norikra
6
+ type norikra_filter
7
7
  norikra localhost:26571 # this is default
8
8
 
9
9
  remove_tag_prefix event
@@ -1,9 +1,8 @@
1
1
  <match event.*>
2
- type norikra
2
+ type norikra_filter
3
3
  norikra localhost:26571
4
4
 
5
5
  <server>
6
- execute yes # (default)no
7
6
  path /home/user/.rbenv/versions/jruby-1.7.4/bin/norikra
8
7
  </server>
9
8
 
@@ -24,13 +23,13 @@
24
23
  # include foo,bar,baz
25
24
  # include_regexp status.*
26
25
  field_boolean flag
27
- field_int status
28
- field_long duration,bytes
26
+ field_integer status,duration,bytes
29
27
 
30
28
  <query>
31
29
  name pv_${target}
32
30
  expression SELECT count(*) AS cnt FROM ${target}.win:time_batch(1 minutes) WHERE not flag
33
31
  tag pv.${target}
32
+ # group pv_query_group # default: nil (default group)
34
33
  fetch_interval 15s # default -> time_batch / 4 ? -> (none) -> 60s
35
34
  # fetch_interval is ignored when <events> section specified
36
35
  </query>
@@ -57,12 +56,12 @@
57
56
  </query>
58
57
  </target>
59
58
 
60
- <events>
59
+ <fetch>
61
60
  method sweep # listen(not implemented)
62
61
  tag query_name
63
62
  # tag field FIELDNAME
64
63
  # tag string TAG_STRING
65
64
  tag_prefix cep
66
- sweep_interval 5s
67
- </events>
65
+ interval 5s
66
+ </fetch>
68
67
  </match>
data/example/test1.conf CHANGED
@@ -3,11 +3,10 @@
3
3
  </source>
4
4
 
5
5
  <match test.*>
6
- type norikra
6
+ type norikra_filter
7
7
  norikra localhost:26571
8
8
  <server>
9
- execute yes
10
- path /Users/tagomoris/.rbenv/versions/jruby-1.7.3/bin/norikra
9
+ path /Users/tagomoris/.rbenv/versions/jruby-1.7.8/bin/norikra # $HOME
11
10
  </server>
12
11
 
13
12
  remove_tag_prefix test
@@ -19,11 +18,11 @@
19
18
  expression SELECT '${target}' as target,count(*) AS cnt FROM ${target}.win:time_batch(30 sec)
20
19
  </query>
21
20
  </default>
22
- <event>
21
+ <fetch>
23
22
  method sweep
24
23
  tag field target
25
24
  tag_prefix count
26
- sweep_interval 5s
25
+ interval 5s
27
26
  </event>
28
27
  </match>
29
28
 
data/example/test1.rb ADDED
@@ -0,0 +1,40 @@
1
+ source {
2
+ type :forward
3
+ }
4
+
5
+ home_dir = ::Object::ENV['HOME']
6
+
7
+ match('test.*') {
8
+ type :norikra_filter
9
+ norikra 'localhost:26571'
10
+ server {
11
+ path "#{home_dir}/.rbenv/versions/jruby-1.7.8/bin/norikra"
12
+ }
13
+
14
+ remove_tag_prefix 'test'
15
+ target_map_tag true
16
+
17
+ default {
18
+ query {
19
+ name "count_${target}"
20
+ expression "SELECT '${target}' as target,count(*) AS cnt FROM ${target}.win:time_batch(30 sec)"
21
+ group "testing"
22
+ tag "count.x.${target}"
23
+ }
24
+ }
25
+
26
+ fetch {
27
+ method :sweep
28
+ tag 'field target'
29
+ tag_prefix 'count'
30
+ interval 5
31
+ }
32
+ }
33
+
34
+ match('fluent.*') {
35
+ type :null
36
+ }
37
+
38
+ match('**') {
39
+ type :stdout
40
+ }
data/example/test2.conf CHANGED
@@ -3,7 +3,7 @@
3
3
  </source>
4
4
 
5
5
  <match {accesslog,applog}.**>
6
- type norikra
6
+ type norikra_filter
7
7
  norikra localhost:26571
8
8
  target_map_tag yes
9
9
 
@@ -14,16 +14,15 @@
14
14
 
15
15
  <target accesslog.**>
16
16
  field_string vhost,path,method,referer,rhost,userlabel,agent,ua_name,ua_category,ua_os,ua_version,ua_vendor
17
- field_int status
18
- field_long bytes,duration
17
+ field_integer status,bytes,duration
19
18
  field_boolean FLAG,status_redirection,status_errors,rhost_internal,suffix_miscfile,suffix_imagefile,agent_bot
20
19
  </target>
21
20
 
22
- <events>
21
+ <fetch>
23
22
  method sweep
24
23
  tag query_name
25
24
  tag_prefix norikra.event
26
- sweep_interval 5s
27
- </events>
25
+ interval 5s
26
+ </fetch>
28
27
  </match>
29
28
 
@@ -0,0 +1,48 @@
1
+ source {
2
+ type :forward
3
+ }
4
+
5
+ match('test.*') {
6
+ type :norikra
7
+ norikra 'localhost:26571'
8
+
9
+ remove_tag_prefix 'test'
10
+ target_map_tag true
11
+
12
+ default {
13
+ include '*'
14
+ exclude 'hhmmss'
15
+ }
16
+
17
+ target('data') {
18
+ field_string 'name'
19
+ field_integer 'age'
20
+ }
21
+ }
22
+
23
+ source {
24
+ type :norikra
25
+
26
+ fetch {
27
+ method :sweep
28
+ # target => nil (group: default)
29
+ tag 'field target'
30
+ tag_prefix 'norikra.query'
31
+ interval 3
32
+ }
33
+
34
+ fetch {
35
+ method :event
36
+ target 'data_count'
37
+ tag 'string norikra.count.data'
38
+ interval 5
39
+ }
40
+ }
41
+
42
+ match('fluent.**') {
43
+ type :null
44
+ }
45
+
46
+ match('**') {
47
+ type :stdout
48
+ }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "fluent-plugin-norikra"
5
- spec.version = "0.0.9"
5
+ spec.version = "0.1.0"
6
6
  spec.authors = ["TAGOMORI Satoshi"]
7
7
  spec.email = ["tagomoris@gmail.com"]
8
8
  spec.description = %q{process events on fluentd with SQL like query, with built-in Norikra server if needed.}
@@ -0,0 +1,75 @@
1
+ require_relative 'norikra/input'
2
+
3
+ require 'norikra-client'
4
+
5
+ module Fluent
6
+ class NorikraInput < Fluent::Input
7
+ include Fluent::NorikraPlugin::InputMixin
8
+
9
+ Fluent::Plugin.register_input('norikra', self)
10
+
11
+ config_param :norikra, :string, :default => 'localhost:26571'
12
+
13
+ config_param :connect_timeout, :integer, :default => nil
14
+ config_param :send_timeout, :integer, :default => nil
15
+ config_param :receive_timeout, :integer, :default => nil
16
+
17
+ # <fetch> tags
18
+ # <fetch>
19
+ # method event
20
+ # target QUERY_NAME
21
+ # interval 5s
22
+ # tag query_name
23
+ # # tag field FIELDNAME
24
+ # # tag string FIXED_STRING
25
+ # tag_prefix norikra.event # actual tag: norikra.event.QUERYNAME
26
+ # </fetch>
27
+ # <fetch>
28
+ # method sweep
29
+ # target QUERY_GROUP # or unspecified => default
30
+ # interval 60s
31
+ # tag field group_by_key
32
+ # tag_prefix norikra.query
33
+ # </fetch>
34
+
35
+ def configure(conf)
36
+ super
37
+
38
+ @host,@port = @norikra.split(':', 2)
39
+ @port = @port.to_i
40
+
41
+ conf.elements.each do |element|
42
+ case element.name
43
+ when 'fetch'
44
+ # ignore: processed in InputMixin, and set @fetch_queue
45
+ else
46
+ raise Fluent::ConfigError, "unknown configuration section name for this plugin: #{element.name}"
47
+ end
48
+ end
49
+
50
+ setup_input(conf)
51
+ end
52
+
53
+ def client(opts={})
54
+ Norikra::Client.new(@host, @port, {
55
+ :connect_timeout => opts[:connect_timeout] || @connect_timeout,
56
+ :send_timeout => opts[:send_timeout] || @send_timeout,
57
+ :receive_timeout => opts[:receive_timeout] || @receive_timeout,
58
+ })
59
+ end
60
+
61
+ def start
62
+ super
63
+ start_input
64
+ end
65
+
66
+ def shutdown
67
+ stop_input
68
+ shutdown_input
69
+ end
70
+
71
+ def fetchable?
72
+ true
73
+ end
74
+ end
75
+ end