def main()

in zktraffic/cli/stats_daemon.py [0:0]


def main(_, opts):

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

  # set proc options before we spawn threads
  process = ProcessOptions()

  if opts.niceness >= 0:
    process.set_niceness(opts.niceness)

  if opts.cpu_affinity:
    process.set_cpu_affinity(opts.cpu_affinity)

  if opts.sampling < 0 or opts.sampling > 1:
    sys.stdout.write("--sampling takes values within [0, 1]\n")
    sys.exit(1)

  stats = StatsServer(opts.iface,
                      opts.zookeeper_port,
                      opts.aggregation_depth,
                      opts.max_results,
                      opts.max_queued_requests,
                      opts.max_queued_replies,
                      opts.max_queued_events,
                      sampling=opts.sampling,
                      include_bytes=not opts.exclude_bytes)

  log.info("Starting with opts: %s" % (opts))

  signal.signal(signal.SIGINT, signal.SIG_DFL)

  server = Server()
  server.mount_routes(DiagnosticsEndpoints())
  server.mount_routes(stats)
  server.run(opts.http_addr, opts.http_port)

  stats.sniffer.join()