embedded Ruby vs. system Ruby


#1

I’m evaluating Sensu for production.

I’ve started with a pretty minimal install of Ubuntu 14.04 Server, and followed the docs on the Sensu website to install Sensu (BTW, the docs are very helpful). I didn’t even have Ruby installed initially, but Sensu appears to include its own Ruby (version 2.0.0 or something) in the .deb package. Eventually I did install the system Ruby afterwards (version 1.9.3).

I’m getting this error in the client log:

{“timestamp”:“2014-08-29T10:34:35.827841-0700”,“level”:“info”,“message”:“received check request”,“check”:{“name”:“cron_check”,“issued”:1409333674,“command”:"/etc/sensu/plugins/check-procs.rb -p crond -C 1 "}}

{“timestamp”:“2014-08-29T10:34:35.879048-0700”,“level”:“info”,“message”:“publishing check result”,“payload”:{“client”:“client1”,“check”:{“name”:“cron_check”,“issued”:1409333674,“command”:"/etc/sensu/plugins/check-procs.rb -p crond -C 1 “,“executed”:1409333675,“duration”:0.051,“output”:”/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- sensu-plugin/check/cli (LoadError)\n\tfrom /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’\n\tfrom /etc/sensu/plugins/check-procs.rb:29:in `’\n",“status”:1}}}

I’ve tried to run that plugin manually but I got the same thing:

$ /etc/sensu/plugins/check-procs.rb -p crond -C 1

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’: cannot load such file – sensu-plugin/check/cli (LoadError)

from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

from /etc/sensu/plugins/check-procs.rb:29:in `<main>'

According to the FAQ, I switched EMBEDDED_RUBY to true and restarted the client. That seemed to have killed the error:

{“timestamp”:“2014-08-29T10:46:35.772363-0700”,“level”:“info”,“message”:“received check request”,“check”:{“name”:“cron_check”,“issued”:1409334394,“command”:"/etc/sensu/plugins/check-procs.rb -p crond -C 1 "}}

{“timestamp”:“2014-08-29T10:46:35.888243-0700”,“level”:“info”,“message”:“publishing check result”,“payload”:{“client”:“client1”,“check”:{“name”:“cron_check”,“issued”:1409334394,“command”:"/etc/sensu/plugins/check-procs.rb -p crond -C 1 ",“executed”:1409334395,“duration”:0.116,“output”:“CheckProcs CRITICAL: Found 0 matching processes; cmd /crond/\n”,“status”:2}}}

But my question is - if the embedded Ruby seems to be preferred, why is EMBEDDED_RUBY not already made true?

And, of course, that still doesn’t solve the problem of running Sensu plugins manually - I still get that error when I run the plugin standalone. What can I do to fix that - add the embedded Ruby to the shell PATH before anything else?


#2

I don't know if it is preferred globally, it can be confusing if you
are not aware of it, which is probably why it is off by default
(principle of least surprise).

Using the embedded ruby does give you the benefit of using Sensu's
ruby, but it also makes it a little less obvious on how to get more
gems installed.
Then, what happens when you start messing up the available gems in the
sensu ruby?

I personally leave the Sensu ruby alone, so I can't possibly break it.
The sensu-omnibus package owns those files. I can install gems
normally by other means if I need them. (into other locations)

Yes, you can set the #! in any ruby script to use the embeded ruby
directly to take advantage of it on a case-by-case basis.
If you want to run in that envinroment for manual testing, you can do
what the init script does yourself:

set_sensu_paths() {
    if [ "x$EMBEDDED_RUBY" = "xtrue" ]; then
        export PATH=/opt/sensu/embedded/bin:$PATH:$PLUGINS_DIR:$HANDLERS_DIR
        export GEM_PATH=/opt/sensu/embedded/lib/ruby/gems/2.0.0:$GEM_PATH
    else
        export PATH=$PATH:$PLUGINS_DIR:$HANDLERS_DIR
    fi
}

Or I think you can just say

/opt/sensu/embedded/bin/ruby your-script.rb

···

On Fri, Aug 29, 2014 at 10:59 AM, Florin Andrei <florin.andrei@gmail.com> wrote:

I'm evaluating Sensu for production.

I've started with a pretty minimal install of Ubuntu 14.04 Server, and
followed the docs on the Sensu website to install Sensu (BTW, the docs are
very helpful). I didn't even have Ruby installed initially, but Sensu
appears to include its own Ruby (version 2.0.0 or something) in the .deb
package. Eventually I did install the system Ruby afterwards (version
1.9.3).

I'm getting this error in the client log:

{"timestamp":"2014-08-29T10:34:35.827841-0700","level":"info","message":"received
check
request","check":{"name":"cron_check","issued":1409333674,"command":"/etc/sensu/plugins/check-procs.rb
-p crond -C 1 "}}
{"timestamp":"2014-08-29T10:34:35.879048-0700","level":"info","message":"publishing
check
result","payload":{"client":"client1","check":{"name":"cron_check","issued":1409333674,"command":"/etc/sensu/plugins/check-procs.rb
-p crond -C 1
","executed":1409333675,"duration":0.051,"output":"/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
`require': cannot load such file -- sensu-plugin/check/cli
(LoadError)\n\tfrom /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'\n\tfrom /etc/sensu/plugins/check-procs.rb:29:in
`<main>'\n","status":1}}}

I've tried to run that plugin manually but I got the same thing:

$ /etc/sensu/plugins/check-procs.rb -p crond -C 1
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load
such file -- sensu-plugin/check/cli (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /etc/sensu/plugins/check-procs.rb:29:in `<main>'

According to the FAQ, I switched EMBEDDED_RUBY to true and restarted the
client. That seemed to have killed the error:

{"timestamp":"2014-08-29T10:46:35.772363-0700","level":"info","message":"received
check
request","check":{"name":"cron_check","issued":1409334394,"command":"/etc/sensu/plugins/check-procs.rb
-p crond -C 1 "}}
{"timestamp":"2014-08-29T10:46:35.888243-0700","level":"info","message":"publishing
check
result","payload":{"client":"client1","check":{"name":"cron_check","issued":1409334394,"command":"/etc/sensu/plugins/check-procs.rb
-p crond -C 1 ","executed":1409334395,"duration":0.116,"output":"CheckProcs
CRITICAL: Found 0 matching processes; cmd /crond/\n","status":2}}}

But my question is - if the embedded Ruby seems to be preferred, why is
EMBEDDED_RUBY not already made true?

And, of course, that still doesn't solve the problem of running Sensu
plugins manually - I still get that error when I run the plugin standalone.
What can I do to fix that - add the embedded Ruby to the shell PATH before
anything else?


#3

Hi,

···

On 30/08/2014 06:03, Kyle Anderson wrote:

I personally leave the Sensu ruby alone, so I can't possibly break it.
The sensu-omnibus package owns those files. I can install gems
normally by other means if I need them. (into other locations)

Yes, you can set the #! in any ruby script to use the embeded ruby
directly to take advantage of it on a case-by-case basis.
If you want to run in that envinroment for manual testing, you can do
what the init script does yourself:

What I have ended up doing is creating a debian package that will install the gems needed by the embedded ruby in an external location. Then, in /etc/default/sensu I define GEM_PATH to point to that location. This way, I use the embedded ruby but I don't mess around with the omnibus package and its gems. Seems to work fine.

J.