How to add gems to Logstash
I am running Logstash 1.4.1, compared to the last one, I cannot find anywhere in my installation folders, contains information about gems (compared to the last code in github there are those gembag.rb, Gemfile, etc.)
My current problem: I need to use multiple gems that Logstash doesn't have in the box, just require 'gemname'
doesn't seem to work. Can anyone lead me to a read that explains how to add these third party gems or show me some sample codes that can do this.
Many thanks!
cd /opt/logstash
env GEM_HOME=vendor/bundle/jruby/1.9 GEM_PATH="" java -jar vendor/jar/jruby-complete-1.7.11.jar -S gem install gemname
If you are installing a local gem file, put the file path in GEM_PATH.
This is what worked for me in logstash 2.0.
env GEM_HOME=/opt/logstash/vendor/bundle/jruby/1.9 /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION
Then I had to edit /opt/logstash/Gemfile
to include the line:
gem "PACKAGE_NAME", "PACKAGE_VERSION"
I know that at some point we also executed yum install ruby-devel
, but I don't remember if this needs to work for this.
For example:
env GEM_HOME=vendor/bundle/jruby/1.9 vendor/jruby/bin/jruby vendor/jruby/bin/gem install zookeeper -v 1.4.11 -V
edit Gemfile:
gem "zookeeper", "1.4.11"
Logstash version independent script (can also be used for logstash 6.0.0):
env GEM_HOME=$$(echo /usr/share/logstash/vendor/bundle/jruby/*/) /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION
In fact, here is the complete script for installing the gem and adding the package metadata to the gem file:
env GEM_HOME=$$(echo /usr/share/logstash/vendor/bundle/jruby/*/) /opt/logstash/vendor/jruby/bin/jruby /opt/logstash/vendor/jruby/bin/gem install PACKAGE_NAME -v PACKAGE_VERSION
echo 'gem \"PACKAGE_NAME\", \"PACKAGE_VERSION\"' >> /usr/share/logstash/Gemfile
Logstash may change the version of JRuby in the future. For example, JRuby 2.3.0 is used in logstash 6.0.0. The above script does not require changing the JRuby version in the path when updating logstash.
I think the simplest way is:
/usr/share/logstash/bin/ruby -S gem install <gem-name>
or
/opt/logstash/bin/ruby -S gem install <gem-name>
Working for me on the latest version of logstash ...