From 93bb8af761dbaa8e19c4660c520db1ee7ba1c70b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 8 Mar 2011 16:30:47 -0800 Subject: linux-listener-stats: favor narrower display if possible No need to make eyes drift :) --- examples/linux-listener-stats.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/linux-listener-stats.rb b/examples/linux-listener-stats.rb index d675ee1..cb48ef7 100755 --- a/examples/linux-listener-stats.rb +++ b/examples/linux-listener-stats.rb @@ -1,4 +1,5 @@ #!/usr/bin/ruby +# -*- encoding: binary -*- $stdout.sync = $stderr.sync = true # this is used to show or watch the number of active and queued # connections on any listener socket from the command line @@ -38,15 +39,22 @@ ARGV.each do |addr| end end +len = "address".size now = nil -fmt = "%20s % 35s % 10u % 10u\n" -$stderr.printf fmt.tr('u','s'), *%w(timestamp address active queued) tcp, unix = [], [] -ARGV.each { |addr| (addr =~ %r{\A/} ? unix : tcp) << addr } +ARGV.each do |addr| + bs = addr.respond_to?(:bytesize) ? addr.bytesize : addr.size + len = bs if bs > len + (addr =~ %r{\A/} ? unix : tcp) << addr +end combined = {} tcp = nil if tcp.empty? unix = nil if unix.empty? +len = 35 if len > 35 +fmt = "%20s % #{len}s % 10u % 10u\n" +$stderr.printf fmt.tr('u','s'), *%w(timestamp address active queued) + begin if now combined.clear -- cgit v1.2.3-24-ge0c7