def __init__(self, settings={}): """ Initializes a new Statsite server instance. All configuration must be done during instantiate. If configuration changes in the future, a new statsite class must be created. """ super(Statsite, self).__init__() # Deep merge the default settings with the given settings self.settings = deep_merge(self.DEFAULT_SETTINGS, settings) # Resolve the classes for each component for component in ["aggregator", "collector", "store"]: key = "_%s_cls" % component value = resolve_class_string(self.settings[component]["class"]) # Delete the class from the settings, since the settings are also # used for initialization, and components don't expect "class" # kwarg. del self.settings[component]["class"] # Set the attribute on ourself for use everywhere else setattr(self, key, value) # Setup the logger self.logger = logging.getLogger("statsite.statsite") self.logger.info( BANNER % { "version": __version__, "collector_cls": self._collector_cls, "aggregator_cls": self._aggregator_cls, "store_cls": self._store_cls, "configuration": pprint.pformat(self.settings, width=60, indent=2), } ) # Setup the store self.logger.debug("Initializing metrics store: %s" % self._store_cls) self.store = self._store_cls(**self.settings["store"]) # Setup the aggregator, provide the store self.settings["aggregator"]["metrics_store"] = self.store self.logger.debug("Initializing aggregator: %s" % self._aggregator_cls) self.aggregator = self._create_aggregator() # Setup the collector, provide the aggregator self.settings["collector"]["aggregator"] = self.aggregator self.logger.debug("Initializing collector: %s" % self._collector_cls) self.collector = self._collector_cls(**self.settings["collector"]) # Setup defaults self.aliveness_check = None self.timer = None
def __init__(self, settings={}): """ Initializes a new Statsite server instance. All configuration must be done during instantiate. If configuration changes in the future, a new statsite class must be created. """ super(Statsite, self).__init__() # Deep merge the default settings with the given settings self.settings = deep_merge(self.DEFAULT_SETTINGS, settings) # Resolve the classes for each component for component in ["aggregator", "collector", "store"]: key = "_%s_cls" % component value = resolve_class_string(self.settings[component]["class"]) # Delete the class from the settings, since the settings are also # used for initialization, and components don't expect "class" # kwarg. del self.settings[component]["class"] # Set the attribute on ourself for use everywhere else setattr(self, key, value) # Setup the logger self.logger = logging.getLogger("statsite.statsite") self.logger.info( BANNER % { "version": __version__, "collector_cls": self._collector_cls, "aggregator_cls": self._aggregator_cls, "store_cls": self._store_cls, "configuration": pprint.pformat( self.settings, width=60, indent=2) }) # Setup the store self.logger.debug("Initializing metrics store: %s" % self._store_cls) self.store = self._store_cls(**self.settings["store"]) # Setup the aggregator, provide the store self.settings["aggregator"]["metrics_store"] = self.store self.logger.debug("Initializing aggregator: %s" % self._aggregator_cls) self.aggregator = self._create_aggregator() # Setup the collector, provide the aggregator self.settings["collector"]["aggregator"] = self.aggregator self.logger.debug("Initializing collector: %s" % self._collector_cls) self.collector = self._collector_cls(**self.settings["collector"]) # Setup defaults self.aliveness_check = None self.timer = None
def includes(self, inclusions): directive = util.IncludeDirective(inclusions) util.deep_merge(self.include_clause, directive.to_dict()) return self
def __init__(self, settings={}): """ Initializes a new Statsite server instance. All configuration must be done during instantiate. If configuration changes in the future, a new statsite class must be created. """ super(Statsite, self).__init__() # Deep merge the default settings with the given settings self.settings = deep_merge(self.DEFAULT_SETTINGS, settings) # Resolve the classes for each component for component in ["aggregator", "collector"]: key = "_%s_cls" % component value = resolve_class_string(self.settings[component]["class"]) # Delete the class from the settings, since the settings are also # used for initialization, and components don't expect "class" # kwarg. del self.settings[component]["class"] # Set the attribute on ourself for use everywhere else setattr(self, key, value) self._store_cls = {} for key, value in self.settings['store'].iteritems(): store_cls_name = 'metrics_store.' + key[0].upper() + key[1:] + 'Store' self._store_cls[key] = resolve_class_string(value.pop('class', store_cls_name)) for metric_type, metric_settings in self.settings["metrics"].iteritems(): metric_cls = metrics.METRIC_TYPES[metric_type] metric_cls.parse_settings(metric_settings) # Setup the logger self.logger = logging.getLogger("statsite.statsite") self.logger.info(BANNER % { "version": __version__, "collector_cls": self._collector_cls, "aggregator_cls": self._aggregator_cls, "store_cls": '\n'.join([' . store.' + k + ': ' + str(v) for k, v in self._store_cls.items()]), "configuration": pprint.pformat(self.settings, width=60, indent=2) }) # Setup the stores self.store = {} for name, cls in self._store_cls.iteritems(): self.logger.debug("Initializing metrics store: %s" % name) self.store[name] = cls() self.store[name].load(self.settings["store"][name]) # Setup the aggregator, provide the store self.settings["aggregator"]["metrics_store"] = self._flush_metrics self.logger.debug("Initializing aggregator: %s" % self._aggregator_cls) self.aggregator = self._create_aggregator() # Setup the collector, provide the aggregator self.settings["collector"]["aggregator"] = self.aggregator self.logger.debug("Initializing collector: %s" % self._collector_cls) self.collector = self._collector_cls(**self.settings["collector"]) # Setup defaults self.aliveness_check = None self.timer = None
def __parse_list(self, include_list): parsed = {} for value in include_list: util.deep_merge(parsed, self.parse_include_args(value)) return parsed