Beispiel #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
Beispiel #2
0
    def bin_path(self):
        """
        Finds and sets as a var the path to the running binary of the mysql server
        """
        if '/' in self.object.cmd:
            self._bin_path = self.object.cmd.split(' ')[0]

        if self._bin_path is None:
            ls_cmd_template = LS_CMD_FREEBSD if host.linux_name(
            ) == 'freebsd' else LS_CMD
            ls_cmd = ls_cmd_template % self.object.pid

            try:
                ls, _ = subp.call(ls_cmd, check=False)
                context.log.debug('ls "%s" output: %s' % (ls_cmd, ls))
            except Exception as e:
                exc_name = e.__class__.__name__

                # this is being kept as an error because it has
                # implications for meta collection success/failure
                context.log.debug(
                    'failed to find MySQL bin path: "%s" failed due to %s' %
                    (ls_cmd, exc_name))
                context.log.debug('additional info:', exc_info=True)
            else:
                try:
                    self._bin_path = ls_parser(ls[0])
                except Exception as e:
                    exc_name = e.__class__.__name__
                    context.log.debug(
                        'failed to parse ls result "%s" due to %s' %
                        (ls[0], exc_name))
                    context.log.debug('additional info:', exc_info=True)

        self.meta['bin_path'] = self._bin_path
Beispiel #3
0
    def bin_path(self):
        """
        Compute the bin_path as part of meta collection to be more tolerant of
        users that utilize `pm.ondemand`.  bin_path is also not required for
        our regular running logic so it can safely be moved down a level (to
        this collector that runs on a regular async basis).

        This used to live in manager._find_all() but it is impossible to cache
        the value there.
        """
        # only compute if bin_path hasn't been found before
        if self._bin_path is None:
            all_pids = [self.object.pid] + self.object.workers

            last_exception = None

            for pid in all_pids:
                ls_cmd_template = LS_CMD_FREEBSD if host.linux_name(
                ) == 'freebsd' else LS_CMD
                ls_cmd = ls_cmd_template % pid

                try:
                    ls, _ = subp.call(ls_cmd)
                    context.log.debug('ls "%s" output: %s' % (ls_cmd, ls))
                except Exception as e:
                    last_exception = e
                else:
                    try:
                        self._bin_path = LS_PARSER(ls[0])
                    except Exception as e:
                        exc_name = e.__class__.__name__
                        context.log.debug(
                            'failed to parse ls result "%s" due to %s' %
                            (ls[0], exc_name))
                        context.log.debug('additional info:', exc_info=True)

                    last_exception = None  # clear last exception for ls
                    break

            # if we never succeeded...log error
            if last_exception:
                exc_name = last_exception.__class__.__name__

                # this is being kept as an error because it has
                # implications for meta collection success/failure
                context.log.debug(
                    'failed to find php-fpm bin path, last attempt: '
                    '"%s" failed due to %s' % (ls_cmd, exc_name))
                context.log.debug('additional info:', exc_info=True)

                # If there is a root_object defined, send an event to the cloud
                if context.objects.root_object:
                    context.objects.root_object.eventd.event(
                        level=INFO, message='php-fpm bin not found')

        self.meta['bin_path'] = self._bin_path
    def __init__(self, **kwargs):
        super(ContainerSystemObject, self).__init__(**kwargs)

        self.imagename = self.data['imagename']

        meta_collector_class = ContainerMetaCollector
        if host.os_name() == 'linux' and host.linux_name() in ('centos',):
            meta_collector_class = DockerCentosMetaCollector

        self.collectors = [
            meta_collector_class(object=self, interval=self.intervals['meta']),
            SystemMetricsCollector(object=self, interval=self.intervals['metrics'])
        ]
Beispiel #5
0
    def __init__(self, **kwargs):
        super(NginxObject, self).__init__(**kwargs)

        meta_collector_class = NginxMetaCollector
        if host.os_name() == 'linux':
            if host.linux_name() in ('ubuntu', 'debian'):
                meta_collector_class = NginxDebianMetaCollector
            elif host.linux_name() in ('centos',):
                meta_collector_class = NginxCentosMetaCollector

        # Collector setup...
        self.collectors = [
            meta_collector_class(
                object=self, interval=self.intervals['meta']
            ),
            NginxMetricsCollector(
                object=self, interval=self.intervals['metrics']
            )
        ]

        self._setup_config_collector()
        self._setup_access_logs()
        self._setup_error_logs()
Beispiel #6
0
    def __init__(self, **kwargs):
        super(SystemObject, self).__init__(**kwargs)

        self.uuid = self.data['uuid']
        self.hostname = self.data['hostname']

        meta_collector_class = SystemCommonMetaCollector
        if host.os_name() == 'linux' and host.linux_name() in ('centos',):
            meta_collector_class = SystemCentosMetaCollector

        self.collectors = [
            meta_collector_class(object=self, interval=self.intervals['meta']),
            SystemMetricsCollector(object=self, interval=self.intervals['metrics'])
        ]
    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
Beispiel #8
0
    def __init__(self, **kwargs):
        super(NginxObject, self).__init__(**kwargs)

        self.root_uuid = self.data.get('root_uuid') or context.objects.root_object.uuid if context.objects.root_object else None
        self.local_id_cache = self.data['local_id']  # Assigned by manager
        self.pid = self.data['pid']
        self.version = self.data['version']
        self.workers = self.data['workers']
        self.prefix = self.data['prefix']
        self.bin_path = self.data['bin_path']
        self.conf_path = self.data['conf_path']

        default_config = context.app_config['containers'][self.type]

        self.upload_config = self.data.get('upload_config') or default_config.get('upload_config', False)
        self.run_config_test = self.data.get('run_test') or default_config.get('run_test', False)
        self.upload_ssl = self.data.get('upload_ssl') or default_config.get('upload_ssl', False)

        self.config = NginxConfig(self.conf_path, prefix=self.prefix)
        self.config.full_parse()

        self.plus_status_external_url, self.plus_status_internal_url = self.get_alive_plus_status_urls()
        self.plus_status_enabled = True if (self.plus_status_external_url or self.plus_status_internal_url) else False

        self.stub_status_url = self.get_alive_stub_status_url()
        self.stub_status_enabled = True if self.stub_status_url else False

        self.processes = []
        self.filters = []

        # filters
        for raw_filter in self.data.get('filters') or []:
            self.filters.append(Filter(**raw_filter))

        # meta
        meta_collector_class = NginxCommonMetaCollector
        if host.os_name() == 'linux':
            if host.linux_name() in ('ubuntu', 'debian'):
                meta_collector_class = NginxDebianMetaCollector
            elif host.linux_name() in ('centos',):
                meta_collector_class = NginxCentosMetaCollector

        self.collectors = [
            meta_collector_class(
                object=self, interval=self.intervals['meta']
            ),
            NginxMetricsCollector(
                object=self, interval=self.intervals['metrics']
            ),
            NginxConfigCollector(
                object=self, interval=self.intervals['configs'],
            )
        ]

        # access logs
        for log_filename, format_name in self.config.access_logs.iteritems():
            log_format = self.config.log_formats.get(format_name)
            try:
                self.collectors.append(
                    NginxAccessLogsCollector(
                        object=self,
                        interval=self.intervals['logs'],
                        filename=log_filename,
                        log_format=log_format,
                    )
                )

                # Send access log discovery event.
                self.eventd.event(level=INFO, message='nginx access log %s found' % log_filename)
            except IOError as e:
                exception_name = e.__class__.__name__
                context.log.error(
                    'failed to start reading log %s due to %s (maybe has no rights?)' %
                    (log_filename, exception_name)
                )
                context.log.debug('additional info:', exc_info=True)

        # error logs
        for log_filename, log_level in self.config.error_logs.iteritems():
            try:
                self.collectors.append(
                    NginxErrorLogsCollector(
                        object=self,
                        interval=self.intervals['logs'],
                        filename=log_filename,
                        level=log_level
                    )
                )

                # Send error log discovery event.
                self.eventd.event(level=INFO, message='nginx error log %s found' % log_filename)
            except IOError as e:
                exception_name = e.__class__.__name__
                context.log.error(
                    'failed to start reading log %s due to %s (maybe has no rights?)' %
                    (log_filename, exception_name)
                )
                context.log.debug('additional info:', exc_info=True)