コード例 #1
0
ファイル: omni.py プロジェクト: XXXu/zktraffic
 def zk_sniffer_factory(port):
     config = ZKSnifferConfig(None)
     config.track_replies = True
     config.zookeeper_port = port
     config.client_port = 0
     if options.include_pings:
         config.include_pings()
     return ZKSniffer(config,
                      zk_printer.request_handler,
                      zk_printer.reply_handler,
                      zk_printer.event_handler,
                      error_to_stderr=True)
コード例 #2
0
ファイル: omni.py プロジェクト: AkihiroSuda/zktraffic
 def zk_sniffer_factory(port):
   config = ZKSnifferConfig('dummy')
   config.track_replies = True
   config.zookeeper_port = port
   config.client_port = 0
   if options.include_pings:
     config.include_pings()
   return ZKSniffer(
     config,
     zk_printer.request_handler,
     zk_printer.reply_handler,
     zk_printer.event_handler,
     error_to_stderr=True
   )
コード例 #3
0
def main(_, options):
    config = SnifferConfig(options.iface)
    config.track_replies = True
    config.zookeeper_port = options.zookeeper_port
    config.max_queued_requests = options.max_queued_requests
    config.client_port = options.client_port if options.client_port != 0 else config.client_port

    if options.excluded_hosts and options.included_hosts:
        sys.stderr.write(
            "The flags --include-host and --exclude-host can't be mixed")
        sys.exit(1)

    if options.excluded_hosts:
        config.excluded_ips += expand_hosts(options.excluded_hosts)
    elif options.included_hosts:
        config.included_ips += expand_hosts(options.included_hosts)

    config.update_filter()

    if options.include_pings:
        config.include_pings()

    config.dump_bad_packet = options.dump_bad_packet

    loopback = options.iface in ["lo", "lo0"]

    if options.unpaired:
        p = UnpairedPrinter(options.colors, loopback)
    else:
        p = DefaultPrinter(options.colors, loopback)
    p.start()

    sniffer = Sniffer(config, p.request_handler, p.reply_handler,
                      p.event_handler)
    sniffer.start()

    try:
        while True:
            time.sleep(60)
    except (KeyboardInterrupt, SystemExit):
        pass

    sys.stdout.write("\033[0m")
    sys.stdout.flush()
コード例 #4
0
ファイル: zk.py プロジェクト: Yasumoto/zktraffic
def main(_, options):
  config = SnifferConfig(options.iface)
  config.track_replies = True
  config.zookeeper_port = options.zookeeper_port
  config.max_queued_requests = options.max_queued_requests
  config.client_port = options.client_port if options.client_port != 0 else config.client_port

  if options.excluded_hosts and options.included_hosts:
    sys.stderr.write("The flags --include-host and --exclude-host can't be mixed")
    sys.exit(1)

  if options.excluded_hosts:
    config.excluded_ips += expand_hosts(options.excluded_hosts)
  elif options.included_hosts:
    config.included_ips += expand_hosts(options.included_hosts)

  config.update_filter()

  if options.include_pings:
    config.include_pings()

  config.dump_bad_packet = options.dump_bad_packet

  loopback = options.iface in ["lo", "lo0"]

  if options.unpaired:
    p = UnpairedPrinter(options.colors, loopback)
  else:
    p = DefaultPrinter(options.colors, loopback)
  p.start()

  sniffer = Sniffer(config, p.request_handler, p.reply_handler, p.event_handler)
  sniffer.start()

  try:
    while True:
      time.sleep(60)
  except (KeyboardInterrupt, SystemExit):
    pass

  sys.stdout.write("\033[0m")
  sys.stdout.flush()
コード例 #5
0
ファイル: zookeeper.py プロジェクト: fuku-ys/earthquake
 def zk_sniffer_factory(port):
     config = ZKSnifferConfig('dummy')
     config.track_replies = True
     config.zookeeper_port = port
     config.client_port = 0
     return ZKSniffer(config, None, None, None, error_to_stderr=True)
コード例 #6
0
ファイル: zk.py プロジェクト: AkihiroSuda/zktraffic
def main(_, options):

  if options.version:
    sys.stdout.write("%s\n" % __version__)
    sys.exit(0)

  config = SnifferConfig(options.iface)
  config.track_replies = True
  config.zookeeper_port = options.zookeeper_port
  config.max_queued_requests = options.max_queued_requests
  config.client_port = options.client_port if options.client_port != 0 else config.client_port

  if options.excluded_hosts and options.included_hosts:
    sys.stderr.write("The flags --include-host and --exclude-host can't be mixed.\n")
    sys.exit(1)

  if options.excluded_hosts:
    config.excluded_ips += expand_hosts(options.excluded_hosts)
  elif options.included_hosts:
    config.included_ips += expand_hosts(options.included_hosts)

  config.update_filter()

  if options.include_pings:
    config.include_pings()

  config.dump_bad_packet = options.dump_bad_packet

  loopback = options.iface in ["lo", "lo0"]

  if options.count_requests > 0 and options.measure_latency > 0:
    sys.stderr.write("The flags --count-requests and --measure-latency can't be mixed.\n")
    sys.exit(1)

  if options.count_requests > 0:
    validate_group_by(options.group_by)
    validate_aggregation_depth(options.aggregation_depth)
    p = CountPrinter(options.count_requests, options.group_by, loopback, options.aggregation_depth)
  elif options.measure_latency > 0:
    validate_group_by(options.group_by)
    validate_aggregation_depth(options.aggregation_depth)
    validate_sort_by(options.sort_by)
    p = LatencyPrinter(
      options.measure_latency, options.group_by, loopback, options.aggregation_depth,
      options.sort_by)
  elif options.unpaired:
    p = UnpairedPrinter(options.colors, loopback)
  else:
    p = DefaultPrinter(options.colors, loopback)
  p.start()

  sniffer = Sniffer(
    config,
    p.request_handler,
    p.reply_handler,
    p.event_handler,
    error_to_stderr=True
  )
  sniffer.start()

  try:
    while p.isAlive():
      time.sleep(0.5)
  except (KeyboardInterrupt, SystemExit):
    p.cancel()

  # shutdown sniffer
  sniffer.stop()
  while sniffer.isAlive():
    time.sleep(0.001)

  try:
    sys.stdout.write("\033[0m")
    sys.stdout.flush()
  except IOError: pass
コード例 #7
0
ファイル: test_omni.py プロジェクト: XXXu/zktraffic
 def zk_sniffer_factory(port):
     config = ZKSnifferConfig(None)
     config.track_replies = True
     config.zookeeper_port = port
     config.client_port = 0
     return ZKSniffer(config, None, None, None, error_to_stderr=True)
コード例 #8
0
ファイル: zk.py プロジェクト: XXXu/zktraffic
def main(_, options):

    if options.version:
        sys.stdout.write("%s\n" % __version__)
        sys.exit(0)

    config = SnifferConfig(options.iface)
    config.track_replies = True
    config.zookeeper_port = options.zookeeper_port
    config.max_queued_requests = options.max_queued_requests
    config.client_port = options.client_port if options.client_port != 0 else config.client_port

    if options.excluded_hosts and options.included_hosts:
        sys.stderr.write(
            "The flags --include-host and --exclude-host can't be mixed.\n")
        sys.exit(1)

    if options.excluded_hosts:
        config.excluded_ips += expand_hosts(options.excluded_hosts)
    elif options.included_hosts:
        config.included_ips += expand_hosts(options.included_hosts)

    config.update_filter()

    if options.include_pings:
        config.include_pings()

    config.dump_bad_packet = options.dump_bad_packet

    loopback = options.iface in ["lo", "lo0"]

    if options.count_requests > 0 and options.measure_latency > 0:
        sys.stderr.write(
            "The flags --count-requests and --measure-latency can't be mixed.\n"
        )
        sys.exit(1)

    if options.count_requests > 0:
        validate_group_by(options.group_by)
        validate_aggregation_depth(options.aggregation_depth)
        p = CountPrinter(options.count_requests, options.group_by, loopback,
                         options.aggregation_depth)
    elif options.measure_latency > 0:
        validate_group_by(options.group_by)
        validate_aggregation_depth(options.aggregation_depth)
        validate_sort_by(options.sort_by)
        p = LatencyPrinter(options.measure_latency, options.group_by, loopback,
                           options.aggregation_depth, options.sort_by)
    elif options.unpaired:
        p = UnpairedPrinter(options.colors, loopback)
    else:
        p = DefaultPrinter(options.colors, loopback)
    p.start()

    sniffer = Sniffer(config,
                      p.request_handler,
                      p.reply_handler,
                      p.event_handler,
                      error_to_stderr=True)
    sniffer.start()

    try:
        while p.isAlive():
            time.sleep(0.5)
    except (KeyboardInterrupt, SystemExit):
        p.cancel()

    # shutdown sniffer
    sniffer.stop()
    while sniffer.isAlive():
        time.sleep(0.001)

    try:
        sys.stdout.write("\033[0m")
        sys.stdout.flush()
    except IOError:
        pass