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 unicorn.metrics.queue 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(/unicorn.metrics.queue/) 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 Unicorn 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

hone avatar dominic avatar wuputah avatar

Watchers

James Cloos avatar

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.