コード例 #1
0
ファイル: test_accumulators.py プロジェクト: rgs1/zktraffic
class TestableStatsLoader(object):
  def __init__(self, aggregation_depth, include_bytes=True):
    self._loader = QueueStatsLoader()
    self._accumulator = TestablePerPathAccumulator(aggregation_depth, include_bytes)
    self._loader.register_accumulator('0', self._accumulator)
    self._loader.start()

  @property
  def processed_requests(self):
    return self._accumulator.processed_requests

  @property
  def processed_events(self):
    return self._accumulator.processed_events

  def stop(self):
    self._loader.stop()

  @property
  def handle_request(self):
    return self._loader.handle_request

  @property
  def handle_reply(self):
    return self._loader.handle_reply

  @property
  def handle_event(self):
    return self._loader.handle_event

  @property
  def cur_stats(self):
    return self._accumulator._cur_stats
コード例 #2
0
ファイル: test_accumulators.py プロジェクト: cmgc/zktraffic
class TestableStatsLoader(object):
  def __init__(self, aggregation_depth):
    self._loader = QueueStatsLoader()
    self._accumulator = TestablePerPathAccumulator(aggregation_depth)
    self._loader.register_accumulator('0', self._accumulator)
    self._loader.start()

  @property
  def processed_requests(self):
    return self._accumulator.processed_requests

  @property
  def processed_events(self):
    return self._accumulator.processed_events

  def stop(self):
    self._loader.stop()

  @property
  def handle_request(self):
    return self._loader.handle_request

  @property
  def handle_reply(self):
    return self._loader.handle_reply

  @property
  def handle_event(self):
    return self._loader.handle_event

  @property
  def cur_stats(self):
    return self._accumulator._cur_stats
コード例 #3
0
ファイル: stats_server.py プロジェクト: phobos182/zktraffic
class StatsServer(EndpointsServer):
    def __init__(self,
                 iface,
                 zkport,
                 aggregation_depth,
                 max_results=EndpointsServer.MAX_RESULTS,
                 max_reqs=400000,
                 max_reps=400000,
                 max_events=400000):

        # Forcing a load of the multiprocessing module here
        # seem to be hitting http://bugs.python.org/issue8200
        multiprocessing.current_process().name

        self._max_results = max_results

        self._stats = QueueStatsLoader(max_reqs, max_reps, max_events)

        self._stats.register_accumulator(
            'per_path', PerPathStatsAccumulator(aggregation_depth))
        self._stats.register_accumulator(
            'per_ip', PerIPStatsAccumulator(aggregation_depth))
        self._stats.register_accumulator(
            'per_auth', PerAuthStatsAccumulator(aggregation_depth))

        self._stats.start()

        super(StatsServer,
              self).__init__(iface, zkport, self._stats.handle_request,
                             self._stats.handle_reply,
                             self._stats.handle_event)

    def _get_stats(self, name, prefix=''):
        stats_by_opname = self._stats.stats(name, self._max_results)

        stats = {}
        for opname, opstats in stats_by_opname.items():
            for path, value in opstats.items():
                stats["%s%s%s" % (prefix, opname, path)] = value

        return stats

    @HttpServer.route("/json/paths")
    def json_paths(self):
        return self._get_stats('per_path')

    @HttpServer.route("/json/ips")
    def json_ips(self):
        return self._get_stats('per_ip', 'per_ip/')

    @HttpServer.route("/json/auths")
    def json_auths(self):
        return self._get_stats('per_auth', 'per_auth/')

    @HttpServer.route("/json/auths-dump")
    def json_auths_dump(self):
        return self._stats.auth_by_client
コード例 #4
0
ファイル: stats_server.py プロジェクト: phobos182/zktraffic
class StatsServer(EndpointsServer):
  def __init__(self,
               iface,
               zkport,
               aggregation_depth,
               max_results=EndpointsServer.MAX_RESULTS,
               max_reqs=400000,
               max_reps=400000,
               max_events=400000):

    # Forcing a load of the multiprocessing module here
    # seem to be hitting http://bugs.python.org/issue8200
    multiprocessing.current_process().name

    self._max_results = max_results

    self._stats = QueueStatsLoader(max_reqs, max_reps, max_events)

    self._stats.register_accumulator('per_path', PerPathStatsAccumulator(aggregation_depth))
    self._stats.register_accumulator('per_ip', PerIPStatsAccumulator(aggregation_depth))
    self._stats.register_accumulator('per_auth', PerAuthStatsAccumulator(aggregation_depth))

    self._stats.start()

    super(StatsServer, self).__init__(
      iface, zkport, self._stats.handle_request, self._stats.handle_reply, self._stats.handle_event)

  def _get_stats(self, name, prefix=''):
    stats_by_opname = self._stats.stats(name, self._max_results)

    stats = {}
    for opname, opstats in stats_by_opname.items():
      for path, value in opstats.items():
        stats["%s%s%s" % (prefix, opname, path)] = value

    return stats

  @HttpServer.route("/json/paths")
  def json_paths(self):
    return self._get_stats('per_path')

  @HttpServer.route("/json/ips")
  def json_ips(self):
    return self._get_stats('per_ip', 'per_ip/')

  @HttpServer.route("/json/auths")
  def json_auths(self):
    return self._get_stats('per_auth', 'per_auth/')

  @HttpServer.route("/json/auths-dump")
  def json_auths_dump(self):
    return self._stats.auth_by_client
コード例 #5
0
class StatsServer(EndpointsServer):
  def __init__(self,
               iface,
               zkport,
               aggregation_depth,
               max_results=EndpointsServer.MAX_RESULTS,
               max_reqs=400000,
               max_reps=400000,
               max_events=400000,
               start_sniffer=True,
               timer=None,
               sampling=1.0,
               include_bytes=True):

    # Forcing a load of the multiprocessing module here
    # seem to be hitting http://bugs.python.org/issue8200
    multiprocessing.current_process().name

    self._max_results = max_results

    self._stats = QueueStatsLoader(max_reqs, max_reps, max_events, timer)

    self._stats.register_accumulator(
      'per_path', PerPathStatsAccumulator(aggregation_depth, include_bytes))
    self._stats.register_accumulator(
      'per_ip', PerIPStatsAccumulator(aggregation_depth, include_bytes))
    self._stats.register_accumulator(
      'per_auth', PerAuthStatsAccumulator(aggregation_depth, include_bytes))

    self._stats.start()

    super(StatsServer, self).__init__(
      iface,
      zkport,
      self._stats.handle_request,
      self._stats.handle_reply,
      self._stats.handle_event,
      start_sniffer,
      sampling=sampling)

  def wakeup(self):
    self._stats.wakeup()

  @property
  def has_stats(self):
    return len(self._get_stats('per_path')) > 0

  def _get_stats(self, name, prefix=''):
    stats_by_opname = self._stats.stats(name, self._max_results)

    stats = {}
    for opname, opstats in stats_by_opname.items():
      for path, value in opstats.items():
        stats["%s%s%s" % (prefix, opname, path)] = value

    return stats

  @HttpServer.route("/json/paths")
  def json_paths(self):
    return self._get_stats('per_path')

  @HttpServer.route("/json/ips")
  def json_ips(self):
    return self._get_stats('per_ip', 'per_ip/')

  @HttpServer.route("/json/auths")
  def json_auths(self):
    return self._get_stats('per_auth', 'per_auth/')

  @HttpServer.route("/json/auths-dump")
  def json_auths_dump(self):
    return self._stats.auth_by_client

  @HttpServer.route("/json/info")
  def json_info(self):
    """ general info about this instance """
    proc = ProcessOptions()
    return {
      "uptime": proc.uptime
    }
コード例 #6
0
class StatsServer(EndpointsServer):
  def __init__(self,
               iface,
               zkport,
               aggregation_depth,
               max_results=EndpointsServer.MAX_RESULTS,
               max_reqs=400000,
               max_reps=400000,
               max_events=400000,
               start_sniffer=True,
               timer=None,
               sampling=1.0,
               include_bytes=True):

    # Forcing a load of the multiprocessing module here
    # seem to be hitting http://bugs.python.org/issue8200
    multiprocessing.current_process().name

    self._max_results = max_results

    self._stats = QueueStatsLoader(max_reqs, max_reps, max_events, timer)

    self._stats.register_accumulator(
      'per_path', PerPathStatsAccumulator(aggregation_depth, include_bytes))
    self._stats.register_accumulator(
      'per_ip', PerIPStatsAccumulator(aggregation_depth, include_bytes))
    self._stats.register_accumulator(
      'per_auth', PerAuthStatsAccumulator(aggregation_depth, include_bytes))

    self._stats.start()

    super(StatsServer, self).__init__(
      iface,
      zkport,
      self._stats.handle_request,
      self._stats.handle_reply,
      self._stats.handle_event,
      start_sniffer,
      sampling=sampling)

  def wakeup(self):
    self._stats.wakeup()

  @property
  def has_stats(self):
    return len(self._get_stats('per_path')) > 0

  def _get_stats(self, name, prefix='', output_array=False):
    stats_by_opname = self._stats.stats(name, self._max_results)

    if output_array:
        stats_arr = []
        response.content_type = 'application/json'
    else:
        stats = {}
    for opname, opstats in stats_by_opname.items():
      for path, value in opstats.items():
        if output_array:
            #TODO: split prefix to each own key
            #TODO: when per_ip: split path by ':' and add IPs to their own key
            if prefix.endswith('/'):
                prefix = prefix[:-1]
            tmp_dict = {"opname": opname, "path": "%s%s" % (prefix, path), "value":value}
            stats_arr.append(tmp_dict)
        else:
            stats["%s%s%s" % (prefix, opname, path)] = value
    if output_array:
        stats_json = json.dumps(stats_arr)
        return stats_json
    else:
        return stats

  @HttpServer.route("/json/paths")
  def json_paths(self):
    array_get = HttpServer.request.GET.get("array_out")
    array_output = array_get and array_get.lower() in ['true', '1', 't', 'y', 'yes']
    return self._get_stats('per_path', '', array_output)

  @HttpServer.route("/json/ips")
  def json_ips(self):
    array_get = HttpServer.request.GET.get("array_out")
    array_output = array_get and array_get.lower() in ['true', '1', 't', 'y', 'yes']
    return self._get_stats('per_ip', 'per_ip/', array_output)

  @HttpServer.route("/json/auths")
  def json_auths(self):
    array_get = HttpServer.request.GET.get("array_out")
    array_output = array_get and array_get.lower() in ['true', '1', 't', 'y', 'yes']
    return self._get_stats('per_auth', 'per_auth/', array_output)

  @HttpServer.route("/json/auths-dump")
  def json_auths_dump(self):
    return self._stats.auth_by_client

  @HttpServer.route("/json/info")
  def json_info(self):
    """ general info about this instance """
    proc = ProcessOptions()
    return {
      "uptime": proc.uptime
    }