about summary refs log tree commit homepage
path: root/examples
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-04-07 17:07:42 -0700
committerEric Wong <normalperson@yhbt.net>2010-04-07 17:36:31 -0700
commitc3e9f5ba6fc10397f55941f36da29808a105d248 (patch)
tree705970f479064931ae07cfca0cd44013c113cb8d /examples
downloadraindrops-c3e9f5ba6fc10397f55941f36da29808a105d248.tar.gz
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/linux-tcp-listener-stats.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/linux-tcp-listener-stats.rb b/examples/linux-tcp-listener-stats.rb
new file mode 100755
index 0000000..338c408
--- /dev/null
+++ b/examples/linux-tcp-listener-stats.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/ruby
+
+# this is used to show or watch the number of active and queued
+# connections on any listener socket from the command line
+
+require 'raindrops'
+require 'optparse'
+usage = "Usage: #$0 [--loop] ADDR..."
+ARGV.size > 0 or abort usage
+delay = false
+
+# "normal" exits when driven on the command-line
+trap(:INT) { exit 130 }
+trap(:PIPE) { exit 0 }
+
+opts = OptionParser.new('', 24, '  ') do |opts|
+  opts.banner = usage
+  opts.on('-d', '--delay=delay') { |nr| delay = nr.to_i }
+  opts.parse! ARGV
+end
+
+fmt = "% 19s % 10u % 10u\n"
+printf fmt.tr('u','s'), *%w(address active queued)
+
+begin
+  stats = Raindrops::Linux.tcp_listener_stats(ARGV)
+  stats.each { |addr,stats| printf fmt, addr, stats.active, stats.queued }
+end while delay && sleep(delay)