Пример #1
0
    def _get_auto_config(self, image_name):
        from jmxfetch import get_jmx_checks

        jmx_checknames = get_jmx_checks(auto_conf=True)

        ident = self._get_image_ident(image_name)
        templates = []
        if ident in self.auto_conf_images:
            check_names = self.auto_conf_images[ident]

            for check_name in check_names:
                # get the check class to verify it matches
                check = get_check_class(
                    self.agentConfig,
                    check_name) if check_name not in jmx_checknames else True
                if check is None:
                    log.info("Failed auto configuring check %s for %s." %
                             (check_name, image_name))
                    continue
                auto_conf = get_auto_conf(check_name)
                init_config, instances = auto_conf.get('init_config',
                                                       {}), auto_conf.get(
                                                           'instances', [])
                for instance in instances:
                    templates.append((check_name, init_config, instance or {}))

        return templates
Пример #2
0
def generate_jmx_configs(agentConfig, hostname, checknames=None):
    """Similar logic to load_check_directory for JMX checks"""
    from jmxfetch import get_jmx_checks

    jmx_checks = get_jmx_checks(auto_conf=True)

    if not checknames:
        checknames = jmx_checks
    agentConfig['checksd_hostname'] = hostname

    # the check was not found, try with service discovery
    generated = {}
    for check_name, service_disco_check_config in _service_disco_configs(agentConfig).iteritems():
        if check_name in checknames and check_name in jmx_checks:
            log.debug('Generating JMX config for: %s' % check_name)

            _, (sd_init_config, sd_instances) = service_disco_check_config

            check_config = {'init_config': sd_init_config,
                            'instances': sd_instances}

            try:
                yaml = config_to_yaml(check_config)
                generated["{}_{}".format(check_name, 0)] = yaml
                log.debug("YAML generated: %s", yaml)
            except Exception:
                log.exception("Unable to generate YAML config for %s", check_name)

    return generated
Пример #3
0
    def reload_configs(self, checks_to_reload=set()):
        """Reload the agent configuration and checksd configurations.
           Can also reload only an explicit set of checks."""
        log.info("Attempting a configuration reload...")
        hostname = get_hostname(self._agentConfig)
        jmx_sd_configs = None

        # if no check was given, reload them all
        if not checks_to_reload:
            log.debug("No check list was passed, reloading every check")
            # stop checks
            for check in self._checksd.get('initialized_checks', []):
                check.stop()

            self._checksd = load_check_directory(self._agentConfig, hostname)
            if self._jmx_service_discovery_enabled:
                jmx_sd_configs = generate_jmx_configs(self._agentConfig,
                                                      hostname)
        else:
            new_checksd = copy(self._checksd)
            all_jmx_checks = get_jmx_checks(auto_conf=True)
            jmx_checks = [
                check for check in checks_to_reload if check in all_jmx_checks
            ]
            py_checks = set(checks_to_reload) - set(jmx_checks)
            self.refresh_specific_checks(hostname, new_checksd, py_checks)
            if self._jmx_service_discovery_enabled:
                jmx_sd_configs = generate_jmx_configs(self._agentConfig,
                                                      hostname, jmx_checks)

            # once the reload is done, replace existing checks with the new ones
            self._checksd = new_checksd

        if jmx_sd_configs:
            self._submit_jmx_service_discovery(jmx_sd_configs)

        # Logging
        num_checks = len(self._checksd['initialized_checks'])
        if num_checks > 0:
            opt_msg = " (refreshed %s checks)" % len(
                checks_to_reload) if checks_to_reload else ''

            msg = "Check reload was successful. Running {num_checks} checks{opt_msg}.".format(
                num_checks=num_checks, opt_msg=opt_msg)
            log.info(msg)
        else:
            log.info("No checksd configs found")
Пример #4
0
    def reload_configs(self, checks_to_reload=set()):
        """Reload the agent configuration and checksd configurations.
           Can also reload only an explicit set of checks."""
        log.info("Attempting a configuration reload...")
        hostname = get_hostname(self._agentConfig)
        jmx_sd_configs = None

        # if no check was given, reload them all
        if not checks_to_reload:
            log.debug("No check list was passed, reloading every check")
            # stop checks
            for check in self._checksd.get('initialized_checks', []):
                check.stop()

            self._checksd = load_check_directory(self._agentConfig, hostname)
            if self._jmx_service_discovery_enabled:
                jmx_sd_configs = generate_jmx_configs(self._agentConfig, hostname)
        else:
            new_checksd = copy(self._checksd)
            all_jmx_checks = get_jmx_checks(auto_conf=True)
            jmx_checks = [check for check in checks_to_reload if check in all_jmx_checks]
            py_checks = set(checks_to_reload) - set(jmx_checks)
            self.refresh_specific_checks(hostname, new_checksd, py_checks)
            if self._jmx_service_discovery_enabled:
                jmx_sd_configs = generate_jmx_configs(self._agentConfig, hostname, jmx_checks)

            # once the reload is done, replace existing checks with the new ones
            self._checksd = new_checksd

        if jmx_sd_configs:
            self._submit_jmx_service_discovery(jmx_sd_configs)

        # Logging
        num_checks = len(self._checksd['initialized_checks'])
        if num_checks > 0:
            opt_msg = " (refreshed %s checks)" % len(checks_to_reload) if checks_to_reload else ''

            msg = "Check reload was successful. Running {num_checks} checks{opt_msg}.".format(
                num_checks=num_checks, opt_msg=opt_msg)
            log.info(msg)
        else:
            log.info("No checksd configs found")
Пример #5
0
    def _get_auto_config(self, image_name):
        from jmxfetch import get_jmx_checks

        jmx_checknames = get_jmx_checks(auto_conf=True)

        ident = self._get_image_ident(image_name)
        templates = []
        if ident in self.auto_conf_images:
            check_names = self.auto_conf_images[ident]

            for check_name in check_names:
                # get the check class to verify it matches
                check = get_check_class(self.agentConfig, check_name) if check_name not in jmx_checknames else True
                if check is None:
                    log.info("Failed auto configuring check %s for %s." % (check_name, image_name))
                    continue
                auto_conf = get_auto_conf(check_name)
                init_config, instances = auto_conf.get('init_config', {}), auto_conf.get('instances', [])
                templates.append((check_name, init_config, instances[0] or {}))

        return templates