示例#1
0
def _handle_space_usage_request(state, message, _data):
    log = logging.getLogger("_handle_space_usage_request")
    log.info("request for collection %s" % (message["collection-id"],))

    reply = {
        "message-type"  : "space-usage-reply",
        "router-ident"    : message["router-ident"],
        "collection-id" : message["collection-id"],
        "message-id"    : message["message-id"],
        "result"        : None,
    }

    # get sums of stats from the database
    space_accounting_database = SpaceAccountingDatabase(transaction=False)
    try:
        stats = space_accounting_database.retrieve_collection_stats(
            message["collection-id"]
        )
    except SpaceAccountingDatabasecollectionNotFound, instance:
        error_message = "collection not found %s" % (instance, )
        log.warn(error_message)
        reply["result"] = "unknown-collection"
        reply["error-message"] = error_message
        state["router-server"].queue_message_for_send(reply)
        return
    def setUp(self):
        initialize_logging(_log_path)
        self.tearDown()

        # clear out any old stats
        space_accounting_database = SpaceAccountingDatabase()
        space_accounting_database.clear_collection_stats(_collection_id)
        space_accounting_database.commit()

        self._space_accounting_server_process = start_space_accounting_server(
            _local_node_name, _space_accounting_server_address, _space_accounting_pipeline_address
        )
        poll_result = poll_process(self._space_accounting_server_process)
        self.assertEqual(poll_result, None)
    def _flush_to_database(self, hour):

        if hour not in self._state["data"]:
            self._log.warn("no data for %s" % (hour, ))
            return

        self._log.info("storing data for %s" % (hour, ))
        space_accounting_database = SpaceAccountingDatabase()
        for collection_id, events in self._state["data"][hour].items():
            space_accounting_database.store_collection_stats(
                collection_id,
                hour,
                events.get("bytes_added", 0),
                events.get("bytes_removed", 0),
                events.get("bytes_retrieved", 0)
            )
        space_accounting_database.commit()

        del self._state["data"][hour]
示例#4
0
    def setUp(self):
        initialize_logging(_log_path)
        self.tearDown()

        # clear out any old stats
        space_accounting_database = SpaceAccountingDatabase()
        space_accounting_database.clear_collection_stats(_collection_id)
        space_accounting_database.commit()

        self._space_accounting_server_process = \
            start_space_accounting_server(
                _local_node_name,
                _space_accounting_server_address,
                _space_accounting_pipeline_address
            )
        poll_result = poll_process(self._space_accounting_server_process)
        self.assertEqual(poll_result, None)
示例#5
0
    def _flush_to_database(self, hour):

        if hour not in self._state["data"]:
            self._log.warn("no data for %s" % (hour, ))
            return

        self._log.info("storing data for %s" % (hour, ))
        space_accounting_database = SpaceAccountingDatabase()
        for collection_id, events in self._state["data"][hour].items():
            space_accounting_database.store_collection_stats(
                collection_id,
                hour,
                events.get("bytes_added", 0),
                events.get("bytes_removed", 0),
                events.get("bytes_retrieved", 0)
            )
        space_accounting_database.commit()

        del self._state["data"][hour]