unicorn-status icon indicating copy to clipboard operation
unicorn-status copied to clipboard

What if unicorn is listening on TCP port?

Open thehappycoder opened this issue 11 years ago • 3 comments

Can unicorn-status connect to it?

thehappycoder avatar Aug 26 '13 07:08 thehappycoder

Use this:

require 'rubygems'
require 'unicorn'
threshold = 3

# 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|
  Raindrops::Linux.tcp_listener_stats('127.0.0.1:3001').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

inspire22 avatar Feb 14 '14 20:02 inspire22

Wow, over two years since the original question and this is the first time I've seen this, hahaha. I really suck at GitHub notifications! :) Thanks a lot for your contribution, @inspire22, and your question @thehappycoder. I may try to factor this into the code for use via CLI switch or something in the future.

jahio avatar Sep 06 '15 01:09 jahio

Based on input from @inspire22 I've created the "portnum" branch on this repository with a "new version" that can accept either a socket or a port number as the first argument (and makes the interval argument optional, defaulting to 5 seconds):

./unicorn-status.rb /path/to/my.sock

or

./unicorn-status.rb 8080

I need help testing. I don't currently have a good Unicorn + Linux test environment set up and realized only after this borderline rewrite that, (duh), I can't test these features on MacOS. Thus I'd have to build up a Linux VM, set up the configuration, deploy a test app, etc. etc. before I can even know if this works at all.

Which I'll probably do when I have some time to focus on it; I would today but this already wound up needing way more time/attention than I expected.

https://github.com/jahio/unicorn-status/tree/portnum

jahio avatar Nov 03 '17 18:11 jahio