예제 #1
0
    def test_cassandra_accessor(self):
        settings = {"BG_DRIVER": "cassandra"}
        settings["BG_CASSANDRA_CONTACT_POINTS"] = "localhost"
        settings["BG_CASSANDRA_COMPRESSION"] = True
        settings["BG_CASSANDRA_TIMEOUT"] = 5

        settings = bg_settings.settings_from_confattr(settings)
        accessor = bg_accessor_factory.accessor_from_settings(settings)
        self.assertNotEqual(accessor, None)

        settings["BG_CASSANDRA_COMPRESSION"] = False
        settings = bg_settings.settings_from_confattr(settings)
        accessor = bg_accessor_factory.accessor_from_settings(settings)
        self.assertNotEqual(accessor, None)
예제 #2
0
    def test_cassandra_accessor(self):
        settings = {"BG_DRIVER": "cassandra"}
        settings["BG_CASSANDRA_CONTACT_POINTS"] = "localhost"
        settings["BG_CASSANDRA_COMPRESSION"] = True
        settings["BG_CASSANDRA_TIMEOUT"] = 5

        settings = bg_settings.settings_from_confattr(settings)
        accessor = bg_accessor_factory.accessor_from_settings(settings)
        self.assertNotEqual(accessor, None)

        settings["BG_CASSANDRA_COMPRESSION"] = False
        settings = bg_settings.settings_from_confattr(settings)
        accessor = bg_accessor_factory.accessor_from_settings(settings)
        self.assertNotEqual(accessor, None)
예제 #3
0
    def __init__(self, settings):
        """Create a BigGraphiteDatabase."""
        try:
            super(BigGraphiteDatabase, self).__init__(settings)
        except TypeError:
            # For backward compatibility with 1.0.
            super(BigGraphiteDatabase, self).__init__()

        self._cache = None
        self._accessor = None
        self._tagdb = None
        self._settings = settings
        self._metricsToCreate = queue.Queue()
        self._sync_countdown = 0
        self._sync_every_n_writes = settings.get("BG_SYNC_EVERY_N_WRITES",
                                                 self._SYNC_EVERY_N_WRITES)
        self._creation_rate_limit = settings.get("BG_CREATION_RATE_LIMIT",
                                                 self._CREATION_RATE_LIMIT)

        # We want the metadata to be enabled when the file doesn't exists
        watcher = utils.FileWatcher(self._DISABLE_METADATA_FILENAME)
        self.metadata_switch = utils.FeatureSwitch(watcher, True)

        utils.start_admin(bg_settings.settings_from_confattr(settings))
        self.reactor.addSystemEventTrigger("before", "shutdown", self._flush)
        self.reactor.callInThread(self._createMetrics)
        self._lc = task.LoopingCall(self._background)
        self._lc.start(settings["CARBON_METRIC_INTERVAL"], now=False)
예제 #4
0
 def test_hybrid_accessor(self, cassandra_accessor_mock):
     settings = {
                 "BG_DATA_DRIVER": "cassandra",
                 "BG_METADATA_DRIVER": "memory"
             }
     settings = bg_settings.settings_from_confattr(settings)
     accessor = bg_accessor_factory.accessor_from_settings(settings)
     self.assertNotEqual(accessor, None)
     cassandra_accessor_mock.assert_called_with(enable_metadata=False)
예제 #5
0
 def test_hybrid_accessor(self, cassandra_accessor_mock):
     settings = {
         "BG_DATA_DRIVER": "cassandra",
         "BG_METADATA_DRIVER": "memory"
     }
     settings = bg_settings.settings_from_confattr(settings)
     accessor = bg_accessor_factory.accessor_from_settings(settings)
     self.assertNotEqual(accessor, None)
     cassandra_accessor_mock.assert_called_with(enable_metadata=False)
예제 #6
0
    def run(self, accessor, opts):
        """Ask fake Graphite Web for points.

        See command.CommandBase.
        """
        # import here to make sure everything is setup.
        os.environ["DJANGO_SETTINGS_MODULE"] = "graphite.settings"

        accessor.connect()

        from django.conf import settings as django_settings

        # Disable carbon link (enabled by default)
        django_settings.CARBONLINK_HOSTS = []
        # Make sure logging goes to stderr
        django_settings.LOG_FILE_INFO = "-"
        django_settings.LOG_FILE_EXCEPTION = "-"
        django_settings.LOG_FILE_CACHE = "-"
        django_settings.LOG_FILE_RENDERING = "-"

        from graphite import util as graphite_util
        from biggraphite.plugins import graphite

        settings = bg_settings.settings_from_confattr(opts, prefix="")
        metadata_cache = bg_cache_factory.cache_from_settings(
            accessor, settings)
        metadata_cache.open()

        if opts.profile == "flamegraph":
            flamegraph.start_profile_thread(fd=open("./perf.log", "w"))

        finder = graphite.Finder(directories=[],
                                 accessor=accessor,
                                 metadata_cache=metadata_cache)

        time_start = graphite_util.timestamp(opts.time_start)
        time_end = graphite_util.timestamp(opts.time_end)
        output_csv = opts.output_csv

        results = finder.fetch(opts.patterns, time_start, time_end)
        for i, result in enumerate(results):
            # Change the output to match something that display_metrics
            # can work with.
            metric = _FakeMetric(result["path"])
            time_start, time_end, step = result["time_info"]

            points = []
            for i, v in enumerate(result["values"]):
                v = 0 if v is None else v
                points.append((time_start + step * i, v))

            result = (points, time_start, time_end, step)
            if not opts.no_output:
                self._display_metric(metric, result, output_csv)
예제 #7
0
    def run(self, accessor, opts):
        """Ask fake Graphite Web for points.

        See command.CommandBase.
        """
        # import here to make sure everything is setup.
        os.environ["DJANGO_SETTINGS_MODULE"] = "graphite.settings"

        accessor.connect()

        from django.conf import settings as django_settings

        # Disable carbon link (enabled by default)
        django_settings.CARBONLINK_HOSTS = []
        # Make sure logging goes to stderr
        django_settings.LOG_FILE_INFO = "-"
        django_settings.LOG_FILE_EXCEPTION = "-"
        django_settings.LOG_FILE_CACHE = "-"
        django_settings.LOG_FILE_RENDERING = "-"

        from graphite import util as graphite_util
        from biggraphite.plugins import graphite

        settings = bg_settings.settings_from_confattr(opts, prefix="")
        metadata_cache = bg_cache_factory.cache_from_settings(accessor, settings)
        metadata_cache.open()

        if opts.profile == "flamegraph":
            flamegraph.start_profile_thread(fd=open("./perf.log", "w"))

        finder = graphite.Finder(
            directories=[], accessor=accessor, metadata_cache=metadata_cache
        )

        time_start = graphite_util.timestamp(opts.time_start)
        time_end = graphite_util.timestamp(opts.time_end)
        output_csv = opts.output_csv

        results = finder.fetch(opts.patterns, time_start, time_end)
        for i, result in enumerate(results):
            # Change the output to match something that display_metrics
            # can work with.
            metric = _FakeMetric(result["path"])
            time_start, time_end, step = result["time_info"]

            points = []
            for i, v in enumerate(result["values"]):
                v = 0 if v is None else v
                points.append((time_start + step * i, v))

            result = (points, time_start, time_end, step)
            if not opts.no_output:
                self._display_metric(metric, result, output_csv)
예제 #8
0
def cache_from_settings(accessor, settings, name=None):
    """Get Cache from Graphite-related configuration object.

    Args:
      accessor: a connected Accessor.
      settings: either carbon_conf.Settings or a Django-like settings object.

    Returns:
      Cache (not opened).
    """
    settings = bg_settings.settings_from_confattr(settings)
    return bg_cache_factory.cache_from_settings(accessor, settings, name)
예제 #9
0
def accessor_from_settings(settings):
    """Get Accessor from Graphite-related configuration object.

    Args:
      settings: either carbon_conf.Settings or a Django-like settings object.

    Returns:
      Accessor (not connected).
    """
    settings = bg_settings.settings_from_confattr(settings)
    bg_utils.set_log_level(settings)
    return bg_accessor_factory.accessor_from_settings(settings)
예제 #10
0
    def __init__(self, settings):
        """Create a BigGraphiteDatabase."""
        try:
            super(BigGraphiteDatabase, self).__init__(settings)
        except TypeError:
            # For backward compatibility with 1.0.
            super(BigGraphiteDatabase, self).__init__()

        self._cache = None
        self._accessor = None
        self._tagdb = None
        self._settings = settings
        self._metricsToCreate = queue.Queue()
        self._sync_countdown = 0
        self._sync_every_n_writes = settings.get("BG_SYNC_EVERY_N_WRITES",
                                                 self._SYNC_EVERY_N_WRITES)

        utils.start_admin(bg_settings.settings_from_confattr(settings))
        self.reactor.addSystemEventTrigger("before", "shutdown", self._flush)
        self.reactor.callInThread(self._createMetrics)
        self._lc = task.LoopingCall(self._background)
        self._lc.start(settings["CARBON_METRIC_INTERVAL"], now=False)
예제 #11
0
    def __init__(self, settings):
        """Create a BigGraphiteDatabase."""
        try:
            super(BigGraphiteDatabase, self).__init__(settings)
        except TypeError:
            # For backward compatibility with 1.0.
            super(BigGraphiteDatabase, self).__init__()

        self._cache = None
        self._accessor = None
        self._tagdb = None
        self._settings = settings
        self._metricsToCreate = queue.Queue()
        self._sync_countdown = 0
        self._sync_every_n_writes = settings.get(
            "BG_SYNC_EVERY_N_WRITES", self._SYNC_EVERY_N_WRITES
        )

        utils.start_admin(bg_settings.settings_from_confattr(settings))
        self.reactor.addSystemEventTrigger("before", "shutdown", self._flush)
        self.reactor.callInThread(self._createMetrics)
        self._lc = task.LoopingCall(self._background)
        self._lc.start(settings["CARBON_METRIC_INTERVAL"], now=False)
예제 #12
0
 def test_memory_accessor(self):
     settings = {"BG_DRIVER": "memory"}
     settings = bg_settings.settings_from_confattr(settings)
     accessor = bg_accessor_factory.accessor_from_settings(settings)
     self.assertNotEqual(accessor, None)
예제 #13
0
 def test_memory_accessor(self):
     settings = {"BG_DRIVER": "memory"}
     settings = bg_settings.settings_from_confattr(settings)
     accessor = bg_accessor_factory.accessor_from_settings(settings)
     self.assertNotEqual(accessor, None)