Last active
July 2, 2018 16:34
-
-
Save mowings/3fe0444e5bb45403c478d2d82eb34cbf to your computer and use it in GitHub Desktop.
Unicorn active and queued requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# From: https://github.com/jahio/unicorn-status | |
# You may need to install unicorn: gem install unicorn --no-ri --no-rdoc | |
require 'rubygems' | |
require 'unicorn' | |
# Usage for this program | |
def usage | |
puts "ruby unicorn_status.rb <path to unix socket> <poll interval in seconds>" | |
puts "Polls the given Unix socket every interval in seconds. Will not allow you to drop below 3 second poll intervals." | |
puts "Example: ruby unicorn_status.rb /var/run/engineyard/unicorn_appname.sock 10" | |
end | |
# Look for required args. Throw usage and exit if they don't exist. | |
if ARGV.count < 2 | |
usage | |
exit 1 | |
end | |
# Get the socket and threshold values. | |
socket = ARGV[0] | |
threshold = (ARGV[1]).to_i | |
# Check threshold - is it lte 0? If so, set to 1 second. | |
if threshold.to_i <= 0 | |
threshold = 1 | |
end | |
# Check - does that socket exist? | |
unless File.exist?(socket) | |
puts "Socket file not found: #{socket}" | |
exit 1 | |
end | |
# Poll the given socket every THRESHOLD seconds as specified above. | |
puts "Running infinite loop. Use CTRL+C to exit." | |
puts "------------------------------------------" | |
loop do | |
Raindrops::Linux.unix_listener_stats([socket]).each do |addr, stats| | |
header = "Active Requests Queued Requests" | |
puts header | |
puts stats.active.to_s + stats.queued.to_s.rjust(header.length - stats.active.to_s.length) | |
puts "" # Break line between polling intervals, makes it easier to read | |
end | |
sleep threshold | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment