Subexec::Notifications
Instrumentation for Subexec commands using ActiveSupport::Notifications.
Usage
Read the full document documentation for ActiveSupport::Notifications first. All Subexec events can be subscribed to using the subexec.run key.
ActiveSupport::Notifications.subscribe('subexec.run') do |*args|
Subscribers::SubexecLibrato.new(*args)
end
The payload for events return the Subexec instance via the :sub key as well as the hostname of the machine running the command via the :hostname key. For example:
module Subscribers
class SubexecLibrato < Base
def initialize(*args)
@event = ActiveSupport::Notifications::Event.new(*args)
process
end
def process
sub = @event.payload[:sub]
duration = @event.duration
command = sub.command.split.first
source = @event.payload[:hostname]
Librato::Metrics.submit 'subexec:run' => {type: command, value: duration, source: source}
end
end
end
Learn More
Contributing
The subexec-notifications gem is tested against ActiveSupport v3.x to v4.x. We run our tests on Travis CI in both Ruby 1.9 and 2.0. Check the .travis.yml file for the latest build information.
If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite.
$ bundle install
$ bundle exec rake appraisal:setup
$ bundle exec rake appraisal test
We use the appraisal gem from Thoughtbot to help us generate the individual gemfiles for each ActiveSupport version and to run the tests locally against each generated Gemfile. The rake appraisal test command actually runs our test suite against all ActiveSupport versions in our Appraisal file. If you want to run the tests for a specific ActiveSupport version, use rake -T for a list. For example, the following command will run the tests for ActiveSupport v3.2 only.
$ bundle exec rake appraisal:v32 test
