3 # this is used to show or watch the number of active and queued
4 # connections on any listener socket from the command line
8 usage = "Usage: #$0 [-d delay] ADDR..."
9 ARGV.size > 0 or abort usage
12 # "normal" exits when driven on the command-line
13 trap(:INT) { exit 130 }
14 trap(:PIPE) { exit 0 }
16 opts = OptionParser.new('', 24, ' ') do |opts|
18 opts.on('-d', '--delay=delay') { |nr| delay = nr.to_i }
22 fmt = "% 19s % 10u % 10u\n"
23 printf fmt.tr('u','s'), *%w(address active queued)
26 stats = Raindrops::Linux.tcp_listener_stats(ARGV)
27 stats.each { |addr,stats| printf fmt, addr, stats.active, stats.queued }
28 end while delay && sleep(delay)