Formatted Metrics
Easily produce metrics that can be consumed by l2met or statsd.
Installation
Add this line to your application's Gemfile:
gem 'formatted-metrics'
Usage
Rack
If you want to instrument rack request times:
use Rack::Instrumentation
Instrument
Use Metrics.instrument
to instrument events to STDOUT.
Metrics.instrument 'rack.request' do
@app.call(env)
end
# => 'source=app measure.rack.request=50ms'
Metrics.instrument 'workers.busy', 10, units: 'workers'
# => 'source=app measure.workers.busy=10workers'
Metrics.instrument 'sidekiq.queue', source: 'background' do
yield
end
# => 'source=app.background measure.sidekiq.queue=500ms'
Metrics.group 'sidekiq' do |group|
group.instrument 'queues.process', 100, units: 'jobs'
group.instrument 'workers.busy', 10, units: 'workers'
group.instrument 'queue.time', source: 'worker.1' do
sleep 1
end
end
# => 'source=app measure.sidekiq.queues.processed=100jobs measure.sidekiq.workers.busy=10workers'
# => 'source=app.worker.1 measure.sidekiq.queue.time=1000.00ms'
TODO
- Add Rack middleware for outputting rack performance metrics.
- Instrument some default rails stuff.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request