Plugin Authors: Use Inline Options

February 22 Bullet_white By Andre Bullet_white Posted in Features Bullet_white Comments Comments

This info is for Scout plugin authors. The Scout Agent version 5+ supports options inline in the code. If you're not using inline options, you should. Here's an example from the awesome new Redis monitor plugin:

    class RedisMonitor < Scout::Plugin
      OPTIONS = <<-EOS
      client_port:
        name: Port
        notes: Redis port to pass to the client library.
        default: 6379
      client_db:
        name: Database
        notes: Redis database ID to pass to the client library.
        default: 0
      client_password:
        name: Password
        notes: If you're using Redis' password authentication.
      EOS
...

Using inline options makes the plugin easier to test and troubleshoot, since the Scout agent knows about the options and can utilize the defaults in test mode:

$ scout test redis-info.rb 
== Plugin options: 
1. 'client_port' Default: 6379. Redis port to pass to the client library.
2. 'client_password' If you're using Redis' password authentication.
3. 'client_db' Default: 0. Redis database ID to pass to the client library.
== Running plugin with: client_port=6379; client_db=0
....

By the way, if you want to test the plugin with something other than the default values, just include them like so:

$ scout test redis-info.rb client_password=seekret

Finally, if you're thinking about a new plugin for Scout, we'd love to hear about it. We're always happy to get you started or point you in the right direction. Read more on plugin development here.

Get notified of new posts.

Once a month, we'll deliver a finely-curated selection of optimization tips to your inbox.

Comments

comments powered by Disqus