Giter VIP home page Giter VIP logo

rack-queue-metrics's Introduction

Rack Queue Metrics

Report on queued connections in any Rack-based server using Raindrops and the Raindrops::Linux features.

Usage

First, add rack-queue-metrics to your Gemfile:

gem 'rack-queue-metrics'

Rails

You're done! If you want to instrument queue metrics beyond the default output, you can subscribe to the rack.queue-metrics notifcation in your Rails app. For example, to print queue information to your logs, add the following to `config/initializers/notifcations.rb:

# config/initializers/notifications.rb
ActiveSupport::Notifications.subscribe(/rack.queue-metrics/) do |*args|
  event = ActiveSupport::Notifications::Event.new(*args)
  payload = event.payload

  addr = payload[:addr]
  active = payload[:requests][:active]
  queued = payload[:requests][:queued]
  queue_time = payload[:queue_time]

  puts "STATS addr=#{addr} active=#{active} queued=#{queued} queue_time=#{queue_time} "
end

For more information, see the ActiveSupport::Notification docs.

Sinatra/Rack Apps

Include the Raindrops and Rack::QueueMetrics middleware in your application's config.ru:

  # config.ru
  use Raindrops::Middleware
  use Rack::QueueMetrics::Middleware

Output

With every request, rack-queue-metrics will output a log line with the the following format:

at=metric measure=rack.queue-metrics addr=10.10.10.90:5000 queue_time=0 queue_depth=0

Notifications

The following information is sent in the notification payload:

  • requests[:active]: Number of requests currently being processed by the dyno at the start of the request
  • requests[:queued]: Number of requests waiting to be processed at the start of the request
  • queue_time: Amount of time the current request spent in the queue
  • addr: Address of the dyno processing the request

rack-queue-metrics's People

Contributors

dominic avatar hone avatar jclem avatar svc-scm avatar wuputah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rack-queue-metrics's Issues

NameError on Rack::QueueMetrics::Middleware

I get an error when I start up my Sinatra app on a Unicorn server:

E, [2014-10-23T17:52:48.219194 #62093] ERROR -- : uninitialized constant Rack::QueueMetrics::Middleware (NameError)
/Users/akash/.rvm/gems/ruby-2.0.0-p481/gems/aws-s3-0.6.3/lib/aws/s3/extensions.rb:212:in `const_missing_from_s3_library'
config.ru:11:in `block in <main>'
/Users/akash/.rvm/gems/ruby-2.0.0-p481/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/Users/akash/.rvm/gems/ruby-2.0.0-p481/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/Users/akash/.rvm/gems/ruby-2.0.0-p481/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `eval'

I've got this line in my Gemfile:

gem "rack-queue-metrics"

This is my config.ru:

require 'rack-queue-metrics'
require 'rubygems'
require 'bundler'

Bundler.require

require './app/main.rb'

use Raindrops::Middleware
use Rack::QueueMetrics::Middleware

run ReportService.new

License?

Which license does this project use?
I've seen some of the heroku projects that do have licenses to use an MIT license, but this one doesn't have any.

Typo in README

I guess the example in the readme file should read:

ActiveSupport::Notifications.subscribe(/rack.queue-metrics/)

instead of /unicorn.metrics.queue/?

On heroku: using Raindrops to measure Ruby Rack queue lengths is currently not possible

As per https://devcenter.heroku.com/changelog-items/255 using raindrops to measure Ruby Rack queue lengths is not currently possible.

It might or might not be related that I sometimes see exceptions

Errno::ECONNREFUSED (Connection refused - sendmsg):

where sometimes means either on 100% of requests during a heroku dyno session or never, and that I suspect to originate from raindrops.

I just open this issue to stay informed on any improvements.

Deployment fails due to TypeError during `rake assets:precompile`

With Rails 4.1.2 and rack-queue-metrics 2.0.0, deployment to Heroku fails. Rails initialization fails when doing rake assets:precompile:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       TypeError: no implicit conversion of nil into String
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/rack-queue-metrics-2.0.0/lib/queue-metrics/queue_depth.rb:32:in `+'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/rack-queue-metrics-2.0.0/lib/queue-metrics/queue_depth.rb:32:in `getaddr'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/rack-queue-metrics-2.0.0/lib/queue-metrics/queue_depth.rb:12:in `initialize'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.7/lib/action_dispatch/middleware/stack.rb:43:in `new'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.7/lib/action_dispatch/middleware/stack.rb:43:in `build'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.7/lib/action_dispatch/middleware/stack.rb:118:in `block in build'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.7/lib/action_dispatch/middleware/stack.rb:118:in `each'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.7/lib/action_dispatch/middleware/stack.rb:118:in `inject'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.7/lib/action_dispatch/middleware/stack.rb:118:in `build'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/engine.rb:498:in `app'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/application/finisher.rb:36:in `block in <module:Finisher>'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/initializable.rb:30:in `run'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/application.rb:300:in `initialize!'
       /tmp/build_78138ed20671c011118478bd16d67078/config/environment.rb:5:in `<top (required)>'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/application.rb:276:in `require_environment!'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/railties-4.1.7/lib/rails/application.rb:389:in `block in run_tasks_blocks'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/bugsnag-2.5.1/lib/bugsnag/rake.rb:34:in `block in bugsnag_define_task'
       /tmp/build_78138ed20671c011118478bd16d67078/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.2.0/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.