背景
Logstash 是一个用于日志收集、处理、转发的软件,对应 input/filter/output 三个阶段,可以配置多个插件实现流式处理
我们可以自定义开发插件,实现丰富的日志处理功能
参考文档 www.elastic.co/products/lo…
安装 jruby
- Download JRuby from jruby.org/
- Extract JRuby into a directory.
- Add that directory's bin subdirectory to the end of your path.
PATH=$PATH:/path/to/jruby-version/bin/复制代码
- Test it: jruby -v
jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-x86_64]复制代码
安装 Bundler
- 参考文档 bundler.io/
/path/to/jruby-veriosn/bin/jgem install bundler复制代码
- 修改 bundle 下载源
bundle config mirror.https://rubygems.org https://gems.ruby-china.org复制代码
换成国内的下载源后,可以加速依赖安装过程,参考文档 gems.ruby-china.org/
使用 Logstash plugin 脚本生成插件模板
/path/to/logstash-version/bin/logstash-plugin generate --type input --name demo --path /path/to/plugins复制代码
安装 Logstash plugin 需要的依赖
cd /path/to/plugins/logstash-input-demo复制代码
修改 logstash-input-demo.gemspec 文件中 TODO 相关的内容,然后执行安装依赖:
bundle install复制代码
测试插件
bundle exec rspec复制代码
参考文档 [rspec.info/](http://rs…
生成 gem 包
/path/to/jruby-veriosn/bin/gem build {logstash-filter-example}.gemspec复制代码
安装&查看插件
/path/to/logstash-version/bin/logstash-plugin install /path/to/gemfile复制代码
/path/to/logstash-version/bin/logstash-plugin list复制代码
总结
如果你的插件成功安装,那么就可以在 Logstash 的配置文件中引用了
(还有疑问?联系作者微博/微信 @Ceelog)