fluentd 0.14.4-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (328) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +26 -0
  4. data/.travis.yml +45 -0
  5. data/AUTHORS +2 -0
  6. data/CONTRIBUTING.md +35 -0
  7. data/COPYING +14 -0
  8. data/ChangeLog +276 -0
  9. data/Gemfile +9 -0
  10. data/README.md +51 -0
  11. data/Rakefile +53 -0
  12. data/Vagrantfile +17 -0
  13. data/appveyor.yml +41 -0
  14. data/bin/fluent-debug +5 -0
  15. data/example/copy_roundrobin.conf +39 -0
  16. data/example/filter_stdout.conf +22 -0
  17. data/example/in_forward.conf +11 -0
  18. data/example/in_http.conf +14 -0
  19. data/example/in_out_forward.conf +17 -0
  20. data/example/in_syslog.conf +15 -0
  21. data/example/in_tail.conf +14 -0
  22. data/example/in_tcp.conf +13 -0
  23. data/example/in_udp.conf +13 -0
  24. data/example/multi_filters.conf +61 -0
  25. data/example/out_buffered_null.conf +32 -0
  26. data/example/out_copy.conf +20 -0
  27. data/example/out_file.conf +13 -0
  28. data/example/out_forward.conf +35 -0
  29. data/example/out_forward_buf_file.conf +23 -0
  30. data/example/v0_12_filter.conf +78 -0
  31. data/example/v1_literal_example.conf +36 -0
  32. data/fluent.conf +139 -0
  33. data/fluentd.gemspec +51 -0
  34. data/lib/fluent/agent.rb +194 -0
  35. data/lib/fluent/command/bundler_injection.rb +45 -0
  36. data/lib/fluent/command/cat.rb +319 -0
  37. data/lib/fluent/command/debug.rb +102 -0
  38. data/lib/fluent/command/fluentd.rb +273 -0
  39. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  40. data/lib/fluent/compat/exec_util.rb +129 -0
  41. data/lib/fluent/compat/file_util.rb +54 -0
  42. data/lib/fluent/compat/filter.rb +68 -0
  43. data/lib/fluent/compat/formatter.rb +111 -0
  44. data/lib/fluent/compat/formatter_utils.rb +85 -0
  45. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  46. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  47. data/lib/fluent/compat/input.rb +49 -0
  48. data/lib/fluent/compat/output.rb +677 -0
  49. data/lib/fluent/compat/output_chain.rb +60 -0
  50. data/lib/fluent/compat/parser.rb +180 -0
  51. data/lib/fluent/compat/parser_utils.rb +40 -0
  52. data/lib/fluent/compat/propagate_default.rb +62 -0
  53. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  54. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  55. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  56. data/lib/fluent/compat/socket_util.rb +165 -0
  57. data/lib/fluent/compat/string_util.rb +34 -0
  58. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  59. data/lib/fluent/compat/type_converter.rb +90 -0
  60. data/lib/fluent/config.rb +56 -0
  61. data/lib/fluent/config/basic_parser.rb +123 -0
  62. data/lib/fluent/config/configure_proxy.rb +366 -0
  63. data/lib/fluent/config/dsl.rb +149 -0
  64. data/lib/fluent/config/element.rb +218 -0
  65. data/lib/fluent/config/error.rb +26 -0
  66. data/lib/fluent/config/literal_parser.rb +251 -0
  67. data/lib/fluent/config/parser.rb +107 -0
  68. data/lib/fluent/config/section.rb +212 -0
  69. data/lib/fluent/config/types.rb +136 -0
  70. data/lib/fluent/config/v1_parser.rb +190 -0
  71. data/lib/fluent/configurable.rb +176 -0
  72. data/lib/fluent/daemon.rb +15 -0
  73. data/lib/fluent/engine.rb +220 -0
  74. data/lib/fluent/env.rb +27 -0
  75. data/lib/fluent/event.rb +287 -0
  76. data/lib/fluent/event_router.rb +259 -0
  77. data/lib/fluent/filter.rb +21 -0
  78. data/lib/fluent/formatter.rb +23 -0
  79. data/lib/fluent/input.rb +21 -0
  80. data/lib/fluent/label.rb +38 -0
  81. data/lib/fluent/load.rb +36 -0
  82. data/lib/fluent/log.rb +445 -0
  83. data/lib/fluent/match.rb +141 -0
  84. data/lib/fluent/mixin.rb +31 -0
  85. data/lib/fluent/msgpack_factory.rb +62 -0
  86. data/lib/fluent/output.rb +26 -0
  87. data/lib/fluent/output_chain.rb +23 -0
  88. data/lib/fluent/parser.rb +23 -0
  89. data/lib/fluent/plugin.rb +161 -0
  90. data/lib/fluent/plugin/bare_output.rb +63 -0
  91. data/lib/fluent/plugin/base.rb +130 -0
  92. data/lib/fluent/plugin/buf_file.rb +154 -0
  93. data/lib/fluent/plugin/buf_memory.rb +34 -0
  94. data/lib/fluent/plugin/buffer.rb +603 -0
  95. data/lib/fluent/plugin/buffer/chunk.rb +160 -0
  96. data/lib/fluent/plugin/buffer/file_chunk.rb +323 -0
  97. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  98. data/lib/fluent/plugin/exec_util.rb +22 -0
  99. data/lib/fluent/plugin/file_util.rb +22 -0
  100. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  101. data/lib/fluent/plugin/filter.rb +93 -0
  102. data/lib/fluent/plugin/filter_grep.rb +75 -0
  103. data/lib/fluent/plugin/filter_record_transformer.rb +342 -0
  104. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  105. data/lib/fluent/plugin/formatter.rb +45 -0
  106. data/lib/fluent/plugin/formatter_csv.rb +47 -0
  107. data/lib/fluent/plugin/formatter_hash.rb +29 -0
  108. data/lib/fluent/plugin/formatter_json.rb +44 -0
  109. data/lib/fluent/plugin/formatter_ltsv.rb +41 -0
  110. data/lib/fluent/plugin/formatter_msgpack.rb +29 -0
  111. data/lib/fluent/plugin/formatter_out_file.rb +78 -0
  112. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  113. data/lib/fluent/plugin/formatter_stdout.rb +74 -0
  114. data/lib/fluent/plugin/in_debug_agent.rb +64 -0
  115. data/lib/fluent/plugin/in_dummy.rb +135 -0
  116. data/lib/fluent/plugin/in_exec.rb +149 -0
  117. data/lib/fluent/plugin/in_forward.rb +366 -0
  118. data/lib/fluent/plugin/in_gc_stat.rb +52 -0
  119. data/lib/fluent/plugin/in_http.rb +422 -0
  120. data/lib/fluent/plugin/in_monitor_agent.rb +401 -0
  121. data/lib/fluent/plugin/in_object_space.rb +90 -0
  122. data/lib/fluent/plugin/in_syslog.rb +204 -0
  123. data/lib/fluent/plugin/in_tail.rb +838 -0
  124. data/lib/fluent/plugin/in_tcp.rb +41 -0
  125. data/lib/fluent/plugin/in_udp.rb +37 -0
  126. data/lib/fluent/plugin/in_unix.rb +201 -0
  127. data/lib/fluent/plugin/input.rb +33 -0
  128. data/lib/fluent/plugin/multi_output.rb +95 -0
  129. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  130. data/lib/fluent/plugin/out_buffered_stdout.rb +70 -0
  131. data/lib/fluent/plugin/out_copy.rb +42 -0
  132. data/lib/fluent/plugin/out_exec.rb +114 -0
  133. data/lib/fluent/plugin/out_exec_filter.rb +393 -0
  134. data/lib/fluent/plugin/out_file.rb +167 -0
  135. data/lib/fluent/plugin/out_forward.rb +646 -0
  136. data/lib/fluent/plugin/out_null.rb +27 -0
  137. data/lib/fluent/plugin/out_relabel.rb +28 -0
  138. data/lib/fluent/plugin/out_roundrobin.rb +80 -0
  139. data/lib/fluent/plugin/out_stdout.rb +48 -0
  140. data/lib/fluent/plugin/out_stream.rb +130 -0
  141. data/lib/fluent/plugin/output.rb +1020 -0
  142. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  143. data/lib/fluent/plugin/parser.rb +175 -0
  144. data/lib/fluent/plugin/parser_apache.rb +28 -0
  145. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  146. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  147. data/lib/fluent/plugin/parser_csv.rb +33 -0
  148. data/lib/fluent/plugin/parser_json.rb +79 -0
  149. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  150. data/lib/fluent/plugin/parser_multiline.rb +104 -0
  151. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  152. data/lib/fluent/plugin/parser_none.rb +36 -0
  153. data/lib/fluent/plugin/parser_regexp.rb +73 -0
  154. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  155. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  156. data/lib/fluent/plugin/socket_util.rb +22 -0
  157. data/lib/fluent/plugin/storage.rb +84 -0
  158. data/lib/fluent/plugin/storage_local.rb +132 -0
  159. data/lib/fluent/plugin/string_util.rb +22 -0
  160. data/lib/fluent/plugin_helper.rb +42 -0
  161. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  162. data/lib/fluent/plugin_helper/compat_parameters.rb +224 -0
  163. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  164. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  165. data/lib/fluent/plugin_helper/formatter.rb +149 -0
  166. data/lib/fluent/plugin_helper/inject.rb +125 -0
  167. data/lib/fluent/plugin_helper/parser.rb +147 -0
  168. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  169. data/lib/fluent/plugin_helper/storage.rb +331 -0
  170. data/lib/fluent/plugin_helper/thread.rb +147 -0
  171. data/lib/fluent/plugin_helper/timer.rb +90 -0
  172. data/lib/fluent/plugin_id.rb +63 -0
  173. data/lib/fluent/process.rb +504 -0
  174. data/lib/fluent/registry.rb +99 -0
  175. data/lib/fluent/root_agent.rb +314 -0
  176. data/lib/fluent/rpc.rb +94 -0
  177. data/lib/fluent/supervisor.rb +680 -0
  178. data/lib/fluent/system_config.rb +122 -0
  179. data/lib/fluent/test.rb +56 -0
  180. data/lib/fluent/test/base.rb +85 -0
  181. data/lib/fluent/test/driver/base.rb +179 -0
  182. data/lib/fluent/test/driver/base_owned.rb +70 -0
  183. data/lib/fluent/test/driver/base_owner.rb +125 -0
  184. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  185. data/lib/fluent/test/driver/filter.rb +57 -0
  186. data/lib/fluent/test/driver/formatter.rb +30 -0
  187. data/lib/fluent/test/driver/input.rb +31 -0
  188. data/lib/fluent/test/driver/multi_output.rb +52 -0
  189. data/lib/fluent/test/driver/output.rb +76 -0
  190. data/lib/fluent/test/driver/parser.rb +30 -0
  191. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  192. data/lib/fluent/test/filter_test.rb +77 -0
  193. data/lib/fluent/test/formatter_test.rb +65 -0
  194. data/lib/fluent/test/helpers.rb +79 -0
  195. data/lib/fluent/test/input_test.rb +172 -0
  196. data/lib/fluent/test/log.rb +73 -0
  197. data/lib/fluent/test/output_test.rb +156 -0
  198. data/lib/fluent/test/parser_test.rb +70 -0
  199. data/lib/fluent/time.rb +175 -0
  200. data/lib/fluent/timezone.rb +133 -0
  201. data/lib/fluent/unique_id.rb +39 -0
  202. data/lib/fluent/version.rb +21 -0
  203. data/lib/fluent/winsvc.rb +71 -0
  204. data/test/compat/test_calls_super.rb +166 -0
  205. data/test/compat/test_parser.rb +82 -0
  206. data/test/config/assertions.rb +42 -0
  207. data/test/config/test_config_parser.rb +507 -0
  208. data/test/config/test_configurable.rb +1194 -0
  209. data/test/config/test_configure_proxy.rb +386 -0
  210. data/test/config/test_dsl.rb +415 -0
  211. data/test/config/test_element.rb +403 -0
  212. data/test/config/test_literal_parser.rb +297 -0
  213. data/test/config/test_section.rb +184 -0
  214. data/test/config/test_system_config.rb +120 -0
  215. data/test/config/test_types.rb +171 -0
  216. data/test/helper.rb +119 -0
  217. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  218. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  219. data/test/plugin/data/2010/01/20100102.log +0 -0
  220. data/test/plugin/data/log/bar +0 -0
  221. data/test/plugin/data/log/foo/bar.log +0 -0
  222. data/test/plugin/data/log/test.log +0 -0
  223. data/test/plugin/test_bare_output.rb +118 -0
  224. data/test/plugin/test_base.rb +75 -0
  225. data/test/plugin/test_buf_file.rb +571 -0
  226. data/test/plugin/test_buf_memory.rb +42 -0
  227. data/test/plugin/test_buffer.rb +1200 -0
  228. data/test/plugin/test_buffer_chunk.rb +168 -0
  229. data/test/plugin/test_buffer_file_chunk.rb +771 -0
  230. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  231. data/test/plugin/test_file_util.rb +96 -0
  232. data/test/plugin/test_filter.rb +353 -0
  233. data/test/plugin/test_filter_grep.rb +119 -0
  234. data/test/plugin/test_filter_record_transformer.rb +600 -0
  235. data/test/plugin/test_filter_stdout.rb +211 -0
  236. data/test/plugin/test_formatter_csv.rb +94 -0
  237. data/test/plugin/test_formatter_json.rb +30 -0
  238. data/test/plugin/test_formatter_ltsv.rb +52 -0
  239. data/test/plugin/test_formatter_msgpack.rb +28 -0
  240. data/test/plugin/test_formatter_out_file.rb +95 -0
  241. data/test/plugin/test_formatter_single_value.rb +38 -0
  242. data/test/plugin/test_in_debug_agent.rb +28 -0
  243. data/test/plugin/test_in_dummy.rb +188 -0
  244. data/test/plugin/test_in_exec.rb +133 -0
  245. data/test/plugin/test_in_forward.rb +635 -0
  246. data/test/plugin/test_in_gc_stat.rb +39 -0
  247. data/test/plugin/test_in_http.rb +442 -0
  248. data/test/plugin/test_in_monitor_agent.rb +329 -0
  249. data/test/plugin/test_in_object_space.rb +64 -0
  250. data/test/plugin/test_in_syslog.rb +205 -0
  251. data/test/plugin/test_in_tail.rb +1001 -0
  252. data/test/plugin/test_in_tcp.rb +102 -0
  253. data/test/plugin/test_in_udp.rb +121 -0
  254. data/test/plugin/test_in_unix.rb +126 -0
  255. data/test/plugin/test_input.rb +122 -0
  256. data/test/plugin/test_multi_output.rb +180 -0
  257. data/test/plugin/test_out_buffered_null.rb +79 -0
  258. data/test/plugin/test_out_buffered_stdout.rb +122 -0
  259. data/test/plugin/test_out_copy.rb +160 -0
  260. data/test/plugin/test_out_exec.rb +155 -0
  261. data/test/plugin/test_out_exec_filter.rb +262 -0
  262. data/test/plugin/test_out_file.rb +383 -0
  263. data/test/plugin/test_out_forward.rb +590 -0
  264. data/test/plugin/test_out_null.rb +29 -0
  265. data/test/plugin/test_out_relabel.rb +28 -0
  266. data/test/plugin/test_out_roundrobin.rb +146 -0
  267. data/test/plugin/test_out_stdout.rb +92 -0
  268. data/test/plugin/test_out_stream.rb +93 -0
  269. data/test/plugin/test_output.rb +568 -0
  270. data/test/plugin/test_output_as_buffered.rb +1604 -0
  271. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  272. data/test/plugin/test_output_as_buffered_retries.rb +839 -0
  273. data/test/plugin/test_output_as_buffered_secondary.rb +817 -0
  274. data/test/plugin/test_output_as_standard.rb +374 -0
  275. data/test/plugin/test_owned_by.rb +35 -0
  276. data/test/plugin/test_parser_apache.rb +42 -0
  277. data/test/plugin/test_parser_apache2.rb +38 -0
  278. data/test/plugin/test_parser_apache_error.rb +45 -0
  279. data/test/plugin/test_parser_base.rb +32 -0
  280. data/test/plugin/test_parser_csv.rb +104 -0
  281. data/test/plugin/test_parser_json.rb +107 -0
  282. data/test/plugin/test_parser_labeled_tsv.rb +129 -0
  283. data/test/plugin/test_parser_multiline.rb +100 -0
  284. data/test/plugin/test_parser_nginx.rb +48 -0
  285. data/test/plugin/test_parser_none.rb +53 -0
  286. data/test/plugin/test_parser_regexp.rb +277 -0
  287. data/test/plugin/test_parser_syslog.rb +66 -0
  288. data/test/plugin/test_parser_time.rb +46 -0
  289. data/test/plugin/test_parser_tsv.rb +121 -0
  290. data/test/plugin/test_storage.rb +167 -0
  291. data/test/plugin/test_storage_local.rb +8 -0
  292. data/test/plugin/test_string_util.rb +26 -0
  293. data/test/plugin_helper/test_child_process.rb +608 -0
  294. data/test/plugin_helper/test_compat_parameters.rb +242 -0
  295. data/test/plugin_helper/test_event_emitter.rb +51 -0
  296. data/test/plugin_helper/test_event_loop.rb +52 -0
  297. data/test/plugin_helper/test_formatter.rb +252 -0
  298. data/test/plugin_helper/test_inject.rb +487 -0
  299. data/test/plugin_helper/test_parser.rb +263 -0
  300. data/test/plugin_helper/test_retry_state.rb +399 -0
  301. data/test/plugin_helper/test_storage.rb +521 -0
  302. data/test/plugin_helper/test_thread.rb +164 -0
  303. data/test/plugin_helper/test_timer.rb +131 -0
  304. data/test/scripts/exec_script.rb +32 -0
  305. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  306. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  307. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  308. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  309. data/test/test_config.rb +179 -0
  310. data/test/test_configdsl.rb +148 -0
  311. data/test/test_event.rb +329 -0
  312. data/test/test_event_router.rb +331 -0
  313. data/test/test_event_time.rb +184 -0
  314. data/test/test_filter.rb +121 -0
  315. data/test/test_formatter.rb +319 -0
  316. data/test/test_input.rb +31 -0
  317. data/test/test_log.rb +572 -0
  318. data/test/test_match.rb +137 -0
  319. data/test/test_mixin.rb +351 -0
  320. data/test/test_output.rb +214 -0
  321. data/test/test_plugin_classes.rb +136 -0
  322. data/test/test_plugin_helper.rb +81 -0
  323. data/test/test_process.rb +48 -0
  324. data/test/test_root_agent.rb +278 -0
  325. data/test/test_supervisor.rb +339 -0
  326. data/test/test_time_formatter.rb +186 -0
  327. data/test/test_unique_id.rb +47 -0
  328. metadata +823 -0
@@ -0,0 +1,64 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin/input'
18
+
19
+ module Fluent::Plugin
20
+ class DebugAgentInput < Input
21
+ Fluent::Plugin.register_input('debug_agent', self)
22
+
23
+ def initialize
24
+ require 'drb/drb'
25
+ require 'fluent/plugin/file_util'
26
+ super
27
+ end
28
+
29
+ config_param :bind, :string, default: '0.0.0.0'
30
+ config_param :port, :integer, default: 24230
31
+ config_param :unix_path, :string, default: nil
32
+ #config_param :unix_mode # TODO
33
+ config_param :object, :string, default: 'Fluent::Engine'
34
+
35
+ def configure(conf)
36
+ super
37
+ if @unix_path
38
+ unless ::Fluent::FileUtil.writable?(@unix_path)
39
+ raise Fluent::ConfigError, "in_debug_agent: `#{@unix_path}` is not writable"
40
+ end
41
+ end
42
+ end
43
+
44
+ def start
45
+ super
46
+
47
+ if @unix_path
48
+ require 'drb/unix'
49
+ uri = "drbunix:#{@unix_path}"
50
+ else
51
+ uri = "druby://#{@bind}:#{@port}"
52
+ end
53
+ log.info "listening dRuby", uri: uri, object: @object
54
+ obj = eval(@object)
55
+ @server = DRb::DRbServer.new(uri, obj)
56
+ end
57
+
58
+ def shutdown
59
+ @server.stop_service if @server
60
+
61
+ super
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,135 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'json'
18
+
19
+ require 'fluent/plugin/input'
20
+ require 'fluent/config/error'
21
+
22
+ module Fluent::Plugin
23
+ class DummyInput < Input
24
+ Fluent::Plugin.register_input('dummy', self)
25
+
26
+ helpers :thread, :storage
27
+
28
+ BIN_NUM = 10
29
+ DEFAULT_STORAGE_TYPE = 'local'
30
+
31
+ desc "The value is the tag assigned to the generated events."
32
+ config_param :tag, :string
33
+ desc "The number of events in event stream of each emits."
34
+ config_param :size, :integer, default: 1
35
+ desc "It configures how many events to generate per second."
36
+ config_param :rate, :integer, default: 1
37
+ desc "If specified, each generated event has an auto-incremented key field."
38
+ config_param :auto_increment_key, :string, default: nil
39
+ desc "The boolean to suspend-and-resume incremental value after restart"
40
+ config_param :suspend, :bool, default: false
41
+ desc "The dummy data to be generated. An array of JSON hashes or a single JSON hash."
42
+ config_param :dummy, default: [{"message"=>"dummy"}] do |val|
43
+ begin
44
+ parsed = JSON.parse(val)
45
+ rescue JSON::ParserError => ex
46
+ # Fluent::ConfigParseError, "got incomplete JSON" will be raised
47
+ # at literal_parser.rb with --use-v1-config, but I had to
48
+ # take care at here for the case of --use-v0-config.
49
+ raise Fluent::ConfigError, "#{ex.class}: #{ex.message}"
50
+ end
51
+ dummy = parsed.is_a?(Array) ? parsed : [parsed]
52
+ dummy.each_with_index do |e, i|
53
+ raise Fluent::ConfigError, "#{i}th element of dummy, #{e}, is not a hash" unless e.is_a?(Hash)
54
+ end
55
+ dummy
56
+ end
57
+
58
+ def initialize
59
+ super
60
+ @storage = nil
61
+ end
62
+
63
+ def configure(conf)
64
+ super
65
+ @dummy_index = 0
66
+ config = conf.elements.select{|e| e.name == 'storage' }.first
67
+ @storage = storage_create(usage: 'suspend', conf: config, default_type: DEFAULT_STORAGE_TYPE)
68
+ end
69
+
70
+ def start
71
+ super
72
+
73
+ @storage.put(:increment_value, 0) unless @storage.get(:increment_value)
74
+ @storage.put(:dummy_index, 0) unless @storage.get(:dummy_index)
75
+
76
+ if @auto_increment_key && !@storage.get(:auto_increment_value)
77
+ @storage.put(:auto_increment_value, -1)
78
+ end
79
+
80
+ thread_create(:dummy_input, &method(:run))
81
+ end
82
+
83
+ def run
84
+ batch_num = (@rate / BIN_NUM).to_i
85
+ residual_num = (@rate % BIN_NUM)
86
+ while thread_current_running?
87
+ current_time = Time.now.to_i
88
+ BIN_NUM.times do
89
+ break unless (thread_current_running? && Time.now.to_i <= current_time)
90
+ wait(0.1) { emit(batch_num) }
91
+ end
92
+ emit(residual_num) if thread_current_running?
93
+ # wait for next second
94
+ while thread_current_running? && Time.now.to_i <= current_time
95
+ sleep 0.01
96
+ end
97
+ end
98
+ end
99
+
100
+ def emit(num)
101
+ begin
102
+ if @size > 1
103
+ num.times do
104
+ router.emit_array(@tag, Array.new(@size) { [Fluent::Engine.now, generate] })
105
+ end
106
+ else
107
+ num.times { router.emit(@tag, Fluent::Engine.now, generate) }
108
+ end
109
+ rescue => _
110
+ # ignore all errors not to stop emits by emit errors
111
+ end
112
+ end
113
+
114
+ def generate
115
+ d = @dummy[@dummy_index]
116
+ unless d
117
+ @dummy_index = 0
118
+ d = @dummy[@dummy_index]
119
+ end
120
+ @dummy_index += 1
121
+ if @auto_increment_key
122
+ d = d.dup
123
+ d[@auto_increment_key] = @storage.update(:auto_increment_value){|v| v + 1 }
124
+ end
125
+ d
126
+ end
127
+
128
+ def wait(time)
129
+ start_time = Time.now
130
+ yield
131
+ sleep_time = time - (Time.now - start_time)
132
+ sleep sleep_time if sleep_time > 0
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,149 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'strptime'
18
+ require 'yajl'
19
+
20
+ require 'fluent/plugin/input'
21
+ require 'fluent/time'
22
+ require 'fluent/timezone'
23
+ require 'fluent/config/error'
24
+
25
+ module Fluent::Plugin
26
+ class ExecInput < Fluent::Plugin::Input
27
+ Fluent::Plugin.register_input('exec', self)
28
+
29
+ helpers :child_process
30
+
31
+ def initialize
32
+ super
33
+ require 'fluent/plugin/exec_util'
34
+ end
35
+
36
+ desc 'The command (program) to execute.'
37
+ config_param :command, :string
38
+ desc 'The format used to map the program output to the incoming event.(tsv,json,msgpack)'
39
+ config_param :format, :string, default: 'tsv'
40
+ desc 'Specify the comma-separated keys when using the tsv format.'
41
+ config_param :keys, default: [] do |val|
42
+ val.split(',')
43
+ end
44
+ desc 'Tag of the output events.'
45
+ config_param :tag, :string, default: nil
46
+ desc 'The key to use as the event tag instead of the value in the event record. '
47
+ config_param :tag_key, :string, default: nil
48
+ desc 'The key to use as the event time instead of the value in the event record.'
49
+ config_param :time_key, :string, default: nil
50
+ desc 'The format of the event time used for the time_key parameter.'
51
+ config_param :time_format, :string, default: nil
52
+ desc 'The interval time between periodic program runs.'
53
+ config_param :run_interval, :time, default: nil
54
+
55
+ def configure(conf)
56
+ super
57
+
58
+ if conf['localtime']
59
+ @localtime = true
60
+ elsif conf['utc']
61
+ @localtime = false
62
+ end
63
+
64
+ if conf['timezone']
65
+ @timezone = conf['timezone']
66
+ Fluent::Timezone.validate!(@timezone)
67
+ end
68
+
69
+ if !@tag && !@tag_key
70
+ raise Fleunt::ConfigError, "'tag' or 'tag_key' option is required on exec input"
71
+ end
72
+
73
+ if @time_key
74
+ if @time_format
75
+ f = @time_format
76
+ @time_parse_proc =
77
+ begin
78
+ strptime = Strptime.new(f)
79
+ Proc.new { |str| Fluent::EventTime.from_time(strptime.exec(str)) }
80
+ rescue
81
+ Proc.new {|str| Fluent::EventTime.from_time(Time.strptime(str, f)) }
82
+ end
83
+ else
84
+ @time_parse_proc = Proc.new {|str| Fluent::EventTime.from_time(Time.at(str.to_f)) }
85
+ end
86
+ end
87
+
88
+ @parser = setup_parser(conf)
89
+ end
90
+
91
+ def setup_parser(conf)
92
+ case @format
93
+ when 'tsv'
94
+ if @keys.empty?
95
+ raise Fluent::ConfigError, "keys option is required on exec input for tsv format"
96
+ end
97
+ Fluent::ExecUtil::TSVParser.new(@keys, method(:on_message))
98
+ when 'json'
99
+ Fluent::ExecUtil::JSONParser.new(method(:on_message))
100
+ when 'msgpack'
101
+ Fluent::ExecUtil::MessagePackParser.new(method(:on_message))
102
+ else
103
+ Fluent::ExecUtil::TextParserWrapperParser.new(conf, method(:on_message))
104
+ end
105
+ end
106
+
107
+ def start
108
+ super
109
+
110
+ if @run_interval
111
+ child_process_execute(:exec_input, @command, interval: @run_interval, mode: [:read]) do |io|
112
+ run(io)
113
+ end
114
+ else
115
+ child_process_execute(:exec_input, @command, immediate: true, mode: [:read]) do |io|
116
+ run(io)
117
+ end
118
+ end
119
+ end
120
+
121
+ def run(io)
122
+ @parser.call(io)
123
+ end
124
+
125
+ private
126
+
127
+ def on_message(record, parsed_time = nil)
128
+ if val = record.delete(@tag_key)
129
+ tag = val
130
+ else
131
+ tag = @tag
132
+ end
133
+
134
+ if parsed_time
135
+ time = parsed_time
136
+ else
137
+ if val = record.delete(@time_key)
138
+ time = @time_parse_proc.call(val)
139
+ else
140
+ time = Fluent::EventTime.now
141
+ end
142
+ end
143
+
144
+ router.emit(tag, time, record)
145
+ rescue => e
146
+ log.error "exec failed to emit", error: e, tag: tag, record: Yajl.dump(record)
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,366 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fcntl'
18
+
19
+ require 'cool.io'
20
+ require 'yajl'
21
+
22
+ require 'fluent/input'
23
+
24
+ module Fluent
25
+ class ForwardInput < Input
26
+ Plugin.register_input('forward', self)
27
+
28
+ LISTEN_PORT = 24224
29
+
30
+ def initialize
31
+ super
32
+ require 'fluent/plugin/socket_util'
33
+ end
34
+
35
+ desc 'The port to listen to.'
36
+ config_param :port, :integer, default: LISTEN_PORT
37
+ desc 'The bind address to listen to.'
38
+ config_param :bind, :string, default: '0.0.0.0'
39
+ config_param :backlog, :integer, default: nil
40
+ # SO_LINGER 0 to send RST rather than FIN to avoid lots of connections sitting in TIME_WAIT at src
41
+ desc 'The timeout time used to set linger option.'
42
+ config_param :linger_timeout, :integer, default: 0
43
+ # This option is for Cool.io's loop wait timeout to avoid loop stuck at shutdown. Almost users don't need to change this value.
44
+ config_param :blocking_timeout, :time, default: 0.5
45
+
46
+ desc 'Log warning if received chunk size is larger than this value.'
47
+ config_param :chunk_size_warn_limit, :size, default: nil
48
+ desc 'Received chunk is dropped if it is larger than this value.'
49
+ config_param :chunk_size_limit, :size, default: nil
50
+ desc 'Skip an event if incoming event is invalid.'
51
+ config_param :skip_invalid_event, :bool, default: false
52
+ desc "The field name of the client's hostname."
53
+ config_param :source_hostname_key, :string, default: nil
54
+
55
+ def configure(conf)
56
+ super
57
+ end
58
+
59
+ def start
60
+ super
61
+
62
+ @loop = Coolio::Loop.new
63
+
64
+ socket_manager_path = ENV['SERVERENGINE_SOCKETMANAGER_PATH']
65
+ if Fluent.windows?
66
+ socket_manager_path = socket_manager_path.to_i
67
+ end
68
+ client = ServerEngine::SocketManager::Client.new(socket_manager_path)
69
+
70
+ @lsock = listen(client)
71
+ @loop.attach(@lsock)
72
+
73
+ @usock = client.listen_udp(@bind, @port)
74
+ @usock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
75
+ @hbr = HeartbeatRequestHandler.new(@usock, method(:on_heartbeat_request))
76
+ @loop.attach(@hbr)
77
+
78
+ @thread = Thread.new(&method(:run))
79
+ end
80
+
81
+ def shutdown
82
+ # In test cases it occasionally appeared that when detaching a watcher, another watcher is also detached.
83
+ # In the case in the iteration of watchers, a watcher that has been already detached is intended to be detached
84
+ # and therfore RuntimeError occurs saying that it is not attached to a loop.
85
+ # It occures only when testing for sending responses to ForwardOutput.
86
+ # Sending responses needs to write the socket that is previously used only to read
87
+ # and a handler has 2 watchers that is used to read and to write.
88
+ # This problem occurs possibly because those watchers are thought to be related to each other
89
+ # and when detaching one of them the other is also detached for some reasons.
90
+ # As a workaround, check if watchers are attached before detaching them.
91
+ @loop.watchers.each {|w| w.detach if w.attached? }
92
+ @loop.stop
93
+ @usock.close
94
+ @thread.join
95
+ @lsock.close
96
+
97
+ super
98
+ end
99
+
100
+ def listen(client)
101
+ log.info "listening fluent socket on #{@bind}:#{@port}"
102
+ sock = client.listen_tcp(@bind, @port)
103
+ s = Coolio::TCPServer.new(sock, nil, Handler, @linger_timeout, log, method(:on_message))
104
+ s.listen(@backlog) unless @backlog.nil?
105
+ s
106
+ end
107
+
108
+ #config_param :path, :string, :default => DEFAULT_SOCKET_PATH
109
+ #def listen
110
+ # if File.exist?(@path)
111
+ # File.unlink(@path)
112
+ # end
113
+ # FileUtils.mkdir_p File.dirname(@path)
114
+ # log.debug "listening fluent socket on #{@path}"
115
+ # Coolio::UNIXServer.new(@path, Handler, method(:on_message))
116
+ #end
117
+
118
+ def run
119
+ @loop.run(@blocking_timeout)
120
+ rescue => e
121
+ log.error "unexpected error", error: e
122
+ log.error_backtrace
123
+ end
124
+
125
+ private
126
+
127
+ # message Entry {
128
+ # 1: long time
129
+ # 2: object record
130
+ # }
131
+ #
132
+ # message Forward {
133
+ # 1: string tag
134
+ # 2: list<Entry> entries
135
+ # 3: object option (optional)
136
+ # }
137
+ #
138
+ # message PackedForward {
139
+ # 1: string tag
140
+ # 2: raw entries # msgpack stream of Entry
141
+ # 3: object option (optional)
142
+ # }
143
+ #
144
+ # message Message {
145
+ # 1: string tag
146
+ # 2: long? time
147
+ # 3: object record
148
+ # 4: object option (optional)
149
+ # }
150
+ def on_message(msg, chunk_size, peeraddr)
151
+ if msg.nil?
152
+ # for future TCP heartbeat_request
153
+ return
154
+ end
155
+
156
+ # TODO: raise an exception if broken chunk is generated by recoverable situation
157
+ unless msg.is_a?(Array)
158
+ log.warn "incoming chunk is broken:", source: source_message(peeraddr), msg: msg
159
+ return
160
+ end
161
+
162
+ tag = msg[0]
163
+ entries = msg[1]
164
+
165
+ if @chunk_size_limit && (chunk_size > @chunk_size_limit)
166
+ log.warn "Input chunk size is larger than 'chunk_size_limit', dropped:", tag: tag, source: source_message(peeraddr), limit: @chunk_size_limit, size: chunk_size
167
+ return
168
+ elsif @chunk_size_warn_limit && (chunk_size > @chunk_size_warn_limit)
169
+ log.warn "Input chunk size is larger than 'chunk_size_warn_limit':", tag: tag, source: source_message(peeraddr), limit: @chunk_size_warn_limit, size: chunk_size
170
+ end
171
+
172
+ if entries.class == String
173
+ # PackedForward
174
+ option = msg[2]
175
+ size = (option && option['size']) || 0
176
+ es = MessagePackEventStream.new(entries, nil, size.to_i)
177
+ es = check_and_skip_invalid_event(tag, es, peeraddr) if @skip_invalid_event
178
+ es = add_source_host(es, peeraddr[2]) if @source_hostname_key
179
+ router.emit_stream(tag, es)
180
+
181
+ elsif entries.class == Array
182
+ # Forward
183
+ es = if @skip_invalid_event
184
+ check_and_skip_invalid_event(tag, entries, peeraddr)
185
+ else
186
+ es = MultiEventStream.new
187
+ entries.each { |e|
188
+ record = e[1]
189
+ next if record.nil?
190
+ time = e[0]
191
+ time = (now ||= Engine.now) if time.to_i == 0
192
+ es.add(time, record)
193
+ }
194
+ es
195
+ end
196
+ es = add_source_host(es, peeraddr[2]) if @source_hostname_key
197
+ router.emit_stream(tag, es)
198
+ option = msg[2]
199
+
200
+ else
201
+ # Message
202
+ time = msg[1]
203
+ record = msg[2]
204
+ if @skip_invalid_event && invalid_event?(tag, time, record)
205
+ log.warn "got invalid event and drop it:", source: source_message(peeraddr), tag: tag, time: time, record: record
206
+ return msg[3] # retry never succeeded so return ack and drop incoming event.
207
+ end
208
+ return if record.nil?
209
+ time = Engine.now if time.to_i == 0
210
+ record[@source_hostname_key] = peeraddr[2] if @source_hostname_key
211
+ router.emit(tag, time, record)
212
+ option = msg[3]
213
+ end
214
+
215
+ # return option for response
216
+ option
217
+ end
218
+
219
+ def invalid_event?(tag, time, record)
220
+ !((time.is_a?(Integer) || time.is_a?(::Fluent::EventTime)) && record.is_a?(Hash) && tag.is_a?(String))
221
+ end
222
+
223
+ def check_and_skip_invalid_event(tag, es, peeraddr)
224
+ new_es = MultiEventStream.new
225
+ es.each { |time, record|
226
+ if invalid_event?(tag, time, record)
227
+ log.warn "skip invalid event:", source: source_message(peeraddr), tag: tag, time: time, record: record
228
+ next
229
+ end
230
+ new_es.add(time, record)
231
+ }
232
+ new_es
233
+ end
234
+
235
+ def add_source_host(es, host)
236
+ new_es = MultiEventStream.new
237
+ es.each { |time, record|
238
+ record[@source_hostname_key] = host
239
+ new_es.add(time, record)
240
+ }
241
+ new_es
242
+ end
243
+
244
+ def source_message(peeraddr)
245
+ _, port, host, addr = peeraddr
246
+ "host: #{host}, addr: #{addr}, port: #{port}"
247
+ end
248
+
249
+ class Handler < Coolio::Socket
250
+ PEERADDR_FAILED = ["?", "?", "name resolusion failed", "?"]
251
+
252
+ def initialize(io, linger_timeout, log, on_message)
253
+ super(io)
254
+
255
+ @peeraddr = nil
256
+ if io.is_a?(TCPSocket) # for unix domain socket support in the future
257
+ @peeraddr = (io.peeraddr rescue PEERADDR_FAILED)
258
+ opt = [1, linger_timeout].pack('I!I!') # { int l_onoff; int l_linger; }
259
+ io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
260
+ end
261
+
262
+ @chunk_counter = 0
263
+ @on_message = on_message
264
+ @log = log
265
+ @log.trace {
266
+ begin
267
+ remote_port, remote_addr = *Socket.unpack_sockaddr_in(@_io.getpeername)
268
+ rescue
269
+ remote_port = nil
270
+ remote_addr = nil
271
+ end
272
+ "accepted fluent socket from '#{remote_addr}:#{remote_port}': object_id=#{self.object_id}"
273
+ }
274
+ end
275
+
276
+ def on_connect
277
+ end
278
+
279
+ def on_read(data)
280
+ first = data[0]
281
+ if first == '{' || first == '['
282
+ m = method(:on_read_json)
283
+ @serializer = :to_json.to_proc
284
+ @y = Yajl::Parser.new
285
+ @y.on_parse_complete = lambda { |obj|
286
+ option = @on_message.call(obj, @chunk_counter, @peeraddr)
287
+ respond option
288
+ @chunk_counter = 0
289
+ }
290
+ else
291
+ m = method(:on_read_msgpack)
292
+ @serializer = :to_msgpack.to_proc
293
+ @u = Fluent::Engine.msgpack_factory.unpacker
294
+ end
295
+
296
+ (class << self; self; end).module_eval do
297
+ define_method(:on_read, m)
298
+ end
299
+ m.call(data)
300
+ end
301
+
302
+ def on_read_json(data)
303
+ @chunk_counter += data.bytesize
304
+ @y << data
305
+ rescue => e
306
+ @log.error "forward error", error: e, error_class: e.class
307
+ @log.error_backtrace
308
+ close
309
+ end
310
+
311
+ def on_read_msgpack(data)
312
+ @chunk_counter += data.bytesize
313
+ @u.feed_each(data) do |obj|
314
+ option = @on_message.call(obj, @chunk_counter, @peeraddr)
315
+ respond option if option
316
+ @chunk_counter = 0
317
+ end
318
+ rescue => e
319
+ @log.error "forward error", error: e, error_class: e.class
320
+ @log.error_backtrace
321
+ close
322
+ end
323
+
324
+ def respond(option)
325
+ if option && option['chunk']
326
+ res = { 'ack' => option['chunk'] }
327
+ write @serializer.call(res)
328
+ @log.trace { "sent response to fluent socket" }
329
+ end
330
+ end
331
+
332
+ def on_close
333
+ @log.trace { "closed socket" }
334
+ end
335
+ end
336
+
337
+ class HeartbeatRequestHandler < Coolio::IO
338
+ def initialize(io, callback)
339
+ super(io)
340
+ @io = io
341
+ @callback = callback
342
+ end
343
+
344
+ def on_readable
345
+ begin
346
+ msg, addr = @io.recvfrom(1024)
347
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
348
+ return
349
+ end
350
+ host = addr[3]
351
+ port = addr[1]
352
+ @callback.call(host, port, msg)
353
+ rescue
354
+ # TODO log?
355
+ end
356
+ end
357
+
358
+ def on_heartbeat_request(host, port, msg)
359
+ #log.trace "heartbeat request from #{host}:#{port}"
360
+ begin
361
+ @usock.send "\0", 0, host, port
362
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
363
+ end
364
+ end
365
+ end
366
+ end