module FWC
Public Class Methods
log()
click to toggle source
# File lib/fwc.rb, line 25 def self.log @logger ||= ::Logger.new(STDOUT).tap do |l| l.level = Logger::INFO l.formatter = proc do |severity, datetime, progname, msg| t = datetime.strftime("%H:%M:%S") "#{t} #{severity}: #{msg}\n" end end end
main(args)
click to toggle source
# File lib/fwc.rb, line 221 def self.main(args) parse_options args matcher = Matcher.new(:key => opts[:key], :tags => opts[:tags]) handlers = [] if opts[:summary] handlers << Summary.new(matcher) end if opts[:raw] handlers << Raw.new(matcher, :threshold => opts[:raw_threshold]) end if handlers.empty? puts "No methods specified" return 1 end EM.run do EM.connect(opts[:host], opts[:port], FWC::TraceConnection, handlers) EM::PeriodicTimer.new(opts[:report_interval]) do handlers.each(&:report!) end end return 0 end
opts()
click to toggle source
# File lib/fwc.rb, line 56 def self.opts @@opts ||= { :debug => false, :host => "localhost", :port => FFWD::Debug::DEFAULT_PORT, :summary => false, :raw => false, :raw_threshold => 100, :report_interval => 10, :key => nil, :tags => nil } end
parse_options(args)
click to toggle source
# File lib/fwc.rb, line 105 def self.parse_options(args) parser.parse args end
parser()
click to toggle source
# File lib/fwc.rb, line 70 def self.parser @@parser ||= OptionParser.new do |o| o.banner = "Usage: fwc [options]" o.on "-d", "--[no-]debug" do |d| opts[:debug] = d end o.on "-s", "--summary", "Show a periodic summary of everything seen" do opts[:summary] = true end o.on "-r", "--raw", "Display raw metrics and events, as soon as they are seen" do opts[:raw] = true end o.on "--raw-threshold <rate>", "Limit of how many messages/s is allowed before disabling output" do |d| opts[:raw_threshold] = d.to_i end o.on "-i", "--report-interval", "Interval in seconds to generate report" do |d| opts[:report_interval] = d.to_i end o.on "--key <key>", "Only handle events and metrics matching the specified key" do |d| opts[:key] = d end o.on "--tag <tag>", "Only handle event and metrics which matches the specified tag" do |d| opts[:tags] ||= [] opts[:tags] << d end end end