Example #1
0
    def _import_collector_class(self, type, target):
        """
        Import a collector class

        :param type: str - Object type name (e.g. 'system' or 'nginx')
        :param target: str - what to collect (e.g. 'meta' or 'metrics')
        :return: A collector class that corresponds with the host's distribution
        """
        distribution = host.linux_name()
        distribution = {
            'ubuntu': '',
            'amzn': 'centos',
            'rhel': 'centos',
            'fedora': 'centos',
            'sles': 'centos'
        }.get(distribution, distribution)

        try:
            class_name = distribution.title() + type.title() + target.title(
            ) + 'Collector'
            class_path = 'amplify.agent.collectors.%s.%s.%s' % (
                type.lower(), target.lower(), class_name)
            cls = loader.import_class(class_path)
        except AttributeError:
            class_name = 'GenericLinux' + type.title() + target.title(
            ) + 'Collector'
            class_path = 'amplify.agent.collectors.%s.%s.%s' % (
                type.lower(), target.lower(), class_name)
            cls = loader.import_class(class_path)

        return cls
    def init_object_managers(self):
        """
        Tries to load and create all internal object managers specified in config
        """
        for object_type in self.object_manager_order:
            try:
                object_manager_classname = self.MANAGER_CLASS % object_type.title(
                )
                manager_class = loader.import_class(
                    self.MANAGER_MODULE %
                    (object_type, object_manager_classname))

                # copy object configs
                if object_type in self.object_managers:
                    object_configs = copy.copy(
                        self.object_managers[object_type].object_configs)
                else:
                    object_configs = None

                self.object_managers[object_type] = manager_class(
                    object_configs=object_configs)
                context.log.debug('loaded "%s" object manager from %s' %
                                  (object_type, manager_class))
            except:
                context.log.error('failed to load %s object manager' %
                                  object_type,
                                  exc_info=True)
def read(config_name, config_file=None):
    """
    Reads specified config and caches it in CONFIG_CACHE dict

    Each config is a python file which can
    Typical name of config for example: /agent/config/app.py

    :param config_name: str config name
    :param config_file: str config file name
    :return: python object
    """
    if config_name not in CONFIG_CACHE:
        full_module_name = 'amplify.agent.common.config.%s' % config_name
        class_name = '%sConfig' % context.environment.title()
        config_object = import_class('%s.%s' % (full_module_name, class_name))(config_file)
        CONFIG_CACHE[config_name] = config_object

    return CONFIG_CACHE[config_name]
def read(config_name, config_file=None):
    """
    Reads specified config and caches it in CONFIG_CACHE dict

    Each config is a python file which can
    Typical name of config for example: /agent/config/app.py

    :param config_name: str config name
    :param config_file: str config file name
    :return: python object
    """
    if config_name not in CONFIG_CACHE:
        full_module_name = 'amplify.agent.common.config.%s' % config_name
        class_name = '%sConfig' % context.environment.title()
        config_object = import_class('%s.%s' % (full_module_name, class_name))(config_file)
        CONFIG_CACHE[config_name] = config_object

    return CONFIG_CACHE[config_name]
Example #5
0
    def _import_collector_class(self, type, target):
        """
        Import a collector class

        :param type: str - Object type name (e.g. 'system' or 'nginx')
        :param target: str - what to collect (e.g. 'meta' or 'metrics')
        :return: A collector class that corresponds with the host's distribution
        """
        distribution = host.linux_name()
        distribution = {"ubuntu": "", "amzn": "centos", "rhel": "centos", "fedora": "centos", "sles": "centos"}.get(
            distribution, distribution
        )

        class_name = distribution.title() + type.title() + target.title() + "Collector"
        class_path = "amplify.agent.collectors.%s.%s.%s" % (type.lower(), target.lower(), class_name)

        cls = loader.import_class(class_path)
        return cls
Example #6
0
    def init_object_managers(self):
        """
        Tries to load and create all object managers specified in config
        """
        object_managers_from_local_config = context.app_config['containers']

        for object_type in self.object_manager_order:
            try:
                object_manager_classname = self.MANAGER_CLASS % object_type.title()
                manager_class = loader.import_class(self.MANAGER_MODULE % (object_type, object_manager_classname))

                # copy object configs
                if object_type in self.object_managers:
                    object_configs = copy.copy(self.object_managers[object_type].object_configs)
                else:
                    object_configs = None

                self.object_managers[object_type] = manager_class(
                    object_configs=object_configs
                )
                context.log.debug('loaded "%s" object manager from %s' % (object_type, manager_class))
            except:
                context.log.error('failed to load %s object manager' % object_type, exc_info=True)