Skip to content
Permalink
Browse files

Add a --host option to look only at the traffic to a specific host

No short flag for that option, to avoid conflicting with --help.
  • Loading branch information...
rgs committed Mar 5, 2013
1 parent 4bd4949 commit b29c5c5496bb0644a923168fe53d703626aa5945
Showing with 13 additions and 1 deletion.
  1. +1 −0 README.md
  2. +5 −0 lib/cmdline.rb
  3. +7 −1 lib/sniffer.rb
@@ -40,6 +40,7 @@ the quickest way to get it running is to:
Usage: mctop [options]
-i, --interface=NIC Network interface to sniff (required)
-p, --port=PORT Network port to sniff on (default 11211)
--host=HOST Network host to sniff on (default all)
-d, --discard=THRESH Discard keys with request/sec rate below THRESH
-r, --refresh=MS Refresh the stats display every MS milliseconds
-h, --help Show usage info
@@ -10,6 +10,11 @@ def self.parse(args)
@config[:nic] = nic
end

@config[:host] = ''
opt.on('--host=HOST', 'Network host to sniff on (default all)') do |host|
@config[:host] = host
end

@config[:port] = 11211
opt.on('-p', '--port=PORT', 'Network port to sniff on (default 11211)') do |port|
@config[:port] = port
@@ -7,6 +7,7 @@ class MemcacheSniffer
def initialize(config)
@source = config[:nic]
@port = config[:port]
@host = config[:host]

@metrics = {}
@metrics[:calls] = {}
@@ -25,7 +26,12 @@ def start

@done = false

cap.setfilter("port #{@port}")
if @host == ""
cap.setfilter("port #{@port}")
else
cap.setfilter("host #{@host} and port #{@port}")
end

cap.loop do |packet|
@metrics[:stats] = cap.stats

0 comments on commit b29c5c5

Please sign in to comment.
You can’t perform that action at this time.