• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python platform.get_os函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.platform.get_os函数的典型用法代码示例。如果您正苦于以下问题:Python get_os函数的具体用法?Python get_os怎么用?Python get_os使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_os函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: load_check

def load_check(name, config, agentConfig):
    if not _is_sdk():
        checksd_path = agentConfig.get('additional_checksd', get_checksd_path(get_os()))

        # find (in checksd_path) and load the check module
        fd, filename, desc = imp.find_module(name, [checksd_path])
        check_module = imp.load_module(name, fd, filename, desc)
    else:
        check_module = _load_sdk_module(name) # parent module

    check_class = None
    classes = inspect.getmembers(check_module, inspect.isclass)
    for _, clsmember in classes:
        if clsmember == AgentCheck:
            continue
        if issubclass(clsmember, AgentCheck):
            check_class = clsmember
            if AgentCheck in clsmember.__bases__:
                continue
            else:
                break
    if check_class is None:
        raise Exception("Unable to import check %s. Missing a class that inherits AgentCheck" % name)

    init_config = config.get('init_config', {})
    instances = config.get('instances')
    agentConfig['checksd_hostname'] = get_hostname(agentConfig)

    # init the check class
    try:
        return check_class(name, init_config, agentConfig, instances=instances)
    except TypeError as e:
        raise Exception("Check is using old API, {0}".format(e))
    except Exception:
        raise
开发者ID:serverdensity,项目名称:sd-agent,代码行数:35,代码来源:common.py


示例2: run_check

def run_check(name, path=None):
    """
    Test custom checks on Windows.
    """
    # Read the config file

    confd_path = path or os.path.join(get_confd_path(get_os()), '%s.yaml' % name)

    try:
        f = open(confd_path)
    except IOError:
        raise Exception('Unable to open configuration at %s' % confd_path)

    config_str = f.read()
    f.close()

    # Run the check
    check, instances = get_check(name, config_str)
    if not instances:
        raise Exception('YAML configuration returned no instances.')
    for instance in instances:
        check.check(instance)
        if check.has_events():
            print "Events:\n"
            pprint(check.get_events(), indent=4)
        print "Metrics:\n"
        pprint(check.get_metrics(), indent=4)
开发者ID:AltSchool,项目名称:dd-agent,代码行数:27,代码来源:debug.py


示例3: get_config_path

def get_config_path(cfg_path=None, os_name=None):
    # Check if there's an override and if it exists
    if cfg_path is not None and os.path.exists(cfg_path):
        return cfg_path

    # Check if there's a config stored in the current agent directory
    try:
        path = os.path.realpath(__file__)
        path = os.path.dirname(path)
        return _config_path(path)
    except PathNotFound as e:
        pass

    if os_name is None:
        os_name = get_os()

    # Check for an OS-specific path, continue on not-found exceptions
    bad_path = ''
    try:
        if os_name == 'windows':
            return _windows_config_path()
        elif os_name == 'mac':
            return _mac_config_path()
        else:
            return _unix_config_path()
    except PathNotFound as e:
        if len(e.args) > 0:
            bad_path = e.args[0]

    # If all searches fail, exit the agent with an error
    sys.stderr.write("Please supply a configuration file at %s or in the directory where "
                     "the Agent is currently deployed.\n" % bad_path)
    sys.exit(3)
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:33,代码来源:config.py


示例4: load_check

def load_check(agentConfig, hostname, checkname):
    """Same logic as load_check_directory except it loads one specific check"""
    agentConfig['checksd_hostname'] = hostname
    osname = get_os()
    checks_places = get_checks_places(osname, agentConfig)
    for config_path in _file_configs_paths(osname, agentConfig):
        check_name = _conf_path_to_check_name(config_path)
        if check_name == checkname:
            conf_is_valid, check_config, invalid_check = _load_file_config(config_path, check_name, agentConfig)

            if invalid_check and not conf_is_valid:
                return invalid_check

            # try to load the check and return the result
            load_success, load_failure = load_check_from_places(check_config, check_name, checks_places, agentConfig)
            return load_success.values()[0] or load_failure

    # the check was not found, try with service discovery
    for check_name, service_disco_check_config in _service_disco_configs(agentConfig).iteritems():
        if check_name == checkname:
            sd_init_config, sd_instances = service_disco_check_config
            check_config = {'init_config': sd_init_config, 'instances': sd_instances}

            # try to load the check and return the result
            load_success, load_failure = load_check_from_places(check_config, check_name, checks_places, agentConfig)
            return load_success.values()[0] or load_failure

    return None
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:28,代码来源:config.py


示例5: get_checksd_path

def get_checksd_path(osname=None):
    if not osname:
        osname = get_os()
    if osname == 'windows':
        return _windows_checksd_path()
    elif osname == 'mac':
        return _mac_checksd_path()
    else:
        return _unix_checksd_path()
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:9,代码来源:config.py


示例6: get_sdk_integrations_path

def get_sdk_integrations_path(osname=None):
    if not osname:
        osname = get_os()
    if osname in ['windows', 'mac']:
        raise PathNotFound()

    cur_path = os.path.dirname(os.path.realpath(__file__))
    path = os.path.join(cur_path, '..', SDK_INTEGRATIONS_DIR)
    if os.path.exists(path):
        return path
    raise PathNotFound(path)
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:11,代码来源:config.py


示例7: get_config

def get_config(parse_args=True, cfg_path=None, options=None):
    if parse_args:
        options, _ = get_parsed_args()

    # General config
    agentConfig = {
        'version': AGENT_VERSION,
        'recv_port':8225,
        'hostname': None,
        'utf8_decoding': False,
        'check_freq': DEFAULT_CHECK_FREQUENCY,
        'run_plugins':[]
    }

    # Find the right config file
    path = os.path.realpath(__file__)
    path = os.path.dirname(path)

    config_path = get_config_path(cfg_path, os_name=get_os())
    config = ConfigParser.ConfigParser()
    config.readfp(skip_leading_wsp(open(config_path)))
    # bulk import
    for option in config.options('Main'):
        agentConfig[option] = config.get('Main', option)

    # Allow an override with the --profile option
    if options is not None and options.profile:
        agentConfig['developer_mode'] = True

    # Core config
    # ap
    if not config.has_option('Main', 'api_key'):
        log.warning(u"No API key was found. Aborting.")
        sys.exit(2)
    if not config.has_option('Main', 'secret_key'):
        log.warning(u"No SECRET key was found. Aborting.")
        sys.exit(2)
    if not config.has_option('Main', 'linklog_url'):
        log.warning(u"No linklog_url was found. Aborting.")
        sys.exit(2)

    if config.has_option('Main', 'check_freq'):
        try:
            agentConfig['check_freq'] = int(config.get('Main', 'check_freq'))
        except Exception:
            pass
    if config.has_option('Main', 'run_plugins'):
        try:
            agentConfig['run_plugins'] = config.get('Main', 'run_plugins').split(',')
        except Exception:
            pass

    return agentConfig
开发者ID:htgeis,项目名称:mystore,代码行数:53,代码来源:agentConfig.py


示例8: load_class

def load_class(check_name, class_name):
    """
    Retrieve a class with the given name within the given check module.
    """
    checksd_path = get_checksd_path(get_os())
    if checksd_path not in sys.path:
        sys.path.append(checksd_path)
    check_module = __import__(check_name)
    classes = inspect.getmembers(check_module, inspect.isclass)
    for name, clsmember in classes:
        if name == class_name:
            return clsmember

    raise Exception(u"Unable to import class {0} from the check module.".format(class_name))
开发者ID:AltSchool,项目名称:dd-agent,代码行数:14,代码来源:common.py


示例9: _get_logging_config

def _get_logging_config(cfg_path=None):
    levels = {
        'CRITICAL': logging.CRITICAL,
        'DEBUG': logging.DEBUG,
        'ERROR': logging.ERROR,
        'FATAL': logging.FATAL,
        'INFO': logging.INFO,
        'WARN': logging.WARN,
        'WARNING': logging.WARNING,
    }

    config_path = get_config_path(cfg_path, os_name=get_os())
    config = ConfigParser.ConfigParser()
    config.readfp(skip_leading_wsp(open(config_path)))

    logging_config = {
        'log_level': logging.INFO,
    }
    if config.has_option('Main', 'log_level'):
        logging_config['log_level'] = levels.get(config.get('Main', 'log_level'))
    if config.has_option('Main', 'disable_file_logging'):
        logging_config['disable_file_logging'] = config.get('Main', 'disable_file_logging').strip().lower() in ['yes', 'true', 1]
    else:
        logging_config['disable_file_logging'] = False

    system_os = get_os()
    global BASE_LOG_DIR
    if system_os != 'windows' and not logging_config['disable_file_logging']:
        if not os.access(BASE_LOG_DIR, os.R_OK | os.W_OK):
            print("{0} dir is not writeable, so change it to local".format(BASE_LOG_DIR))
            BASE_LOG_DIR = "logs"
        logging_config['collector_log_file'] = '{0}/collector.log'.format(BASE_LOG_DIR)
        logging_config['forwarder_log_file'] = '{0}/forwarder.log'.format(BASE_LOG_DIR)
        logging_config['{0}_log_file'.format(__name__)] = '{0}/monitor.log'.format(BASE_LOG_DIR)

    return logging_config
开发者ID:htgeis,项目名称:mystore,代码行数:36,代码来源:agentConfig.py


示例10: get_check_class

def get_check_class(name):
    checksd_path = get_checksd_path(get_os())
    if checksd_path not in sys.path:
        sys.path.append(checksd_path)

    check_module = __import__(name)
    check_class = None
    classes = inspect.getmembers(check_module, inspect.isclass)
    for _, clsmember in classes:
        if clsmember == AgentCheck:
            continue
        if issubclass(clsmember, AgentCheck):
            check_class = clsmember
            if AgentCheck in clsmember.__bases__:
                continue
            else:
                break

    return check_class
开发者ID:AltSchool,项目名称:dd-agent,代码行数:19,代码来源:common.py


示例11: _load_sdk_module

def _load_sdk_module(name):
    sdk_path = get_sdk_integrations_path(get_os())
    module_path = os.path.join(sdk_path, name)
    sdk_module_name = "_{}".format(name)
    if sdk_module_name in sys.modules:
        return sys.modules[sdk_module_name]

    if sdk_path not in sys.path:
        sys.path.append(sdk_path)
    if module_path not in sys.path:
        sys.path.append(module_path)

    fd, filename, desc = imp.find_module('check', [module_path])
    module = imp.load_module("_{}".format(name), fd, filename, desc)
    if fd:
        fd.close()
    # module = __import__(module_name, fromlist=['check'])

    return module
开发者ID:ross,项目名称:dd-agent,代码行数:19,代码来源:common.py


示例12: get_confd_path

def get_confd_path(osname=None):
    try:
        cur_path = os.path.dirname(os.path.realpath(__file__))
        return _confd_path(cur_path)
    except PathNotFound as e:
        pass

    if not osname:
        osname = get_os()
    bad_path = ''
    try:
        if osname == 'windows':
            return _windows_confd_path()
        elif osname == 'mac':
            return _mac_confd_path()
        else:
            return _unix_confd_path()
    except PathNotFound as e:
        if len(e.args) > 0:
            bad_path = e.args[0]

    raise PathNotFound(bad_path)
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:22,代码来源:config.py


示例13: _load_sdk_module

def _load_sdk_module(name):
    try:
        # see whether the check was installed as a wheel package
        return import_module("datadog_checks.{}".format(name))
    except ImportError:
        sdk_path = get_sdk_integrations_path(get_os())
        module_path = os.path.join(sdk_path, name)
        sdk_module_name = "_{}".format(name)
        if sdk_module_name in sys.modules:
            return sys.modules[sdk_module_name]

        if sdk_path not in sys.path:
            sys.path.append(sdk_path)
        if module_path not in sys.path:
            sys.path.append(module_path)

        fd, filename, desc = imp.find_module('check', [module_path])
        module = imp.load_module("_{}".format(name), fd, filename, desc)
        if fd:
            fd.close()
        # module = __import__(module_name, fromlist=['check'])

        return module
开发者ID:serverdensity,项目名称:sd-agent,代码行数:23,代码来源:common.py


示例14: get_check

def get_check(name, config_str):
    from checks import AgentCheck

    checksd_path = get_checksd_path(get_os())
    if checksd_path not in sys.path:
        sys.path.append(checksd_path)
    check_module = __import__(name)
    check_class = None
    classes = inspect.getmembers(check_module, inspect.isclass)
    for name, clsmember in classes:
        if issubclass(clsmember, AgentCheck) and clsmember != AgentCheck:
            check_class = clsmember
            break
    if check_class is None:
        raise Exception("Unable to import check %s. Missing a class that inherits AgentCheck" % name)

    agentConfig = {
        'version': '0.1',
        'api_key': 'tota'
    }

    return check_class.from_yaml(yaml_text=config_str, check_name=name,
                                 agentConfig=agentConfig)
开发者ID:DataDog,项目名称:dd-agent,代码行数:23,代码来源:debug.py


示例15: get_sdk_integrations_path

def get_sdk_integrations_path(osname=None):
    if not osname:
        osname = get_os()

    if os.environ.get('INTEGRATIONS_DIR'):
        if os.environ.get('TRAVIS'):
            path = os.environ['TRAVIS_BUILD_DIR']
        elif os.environ.get('CIRCLECI'):
            path = os.path.join(
                os.environ['HOME'],
                os.environ['CIRCLE_PROJECT_REPONAME']
            )
        elif os.environ.get('APPVEYOR'):
            path = os.environ['APPVEYOR_BUILD_FOLDER']
        else:
            cur_path = os.environ['INTEGRATIONS_DIR']
            path = os.path.join(cur_path, '..') # might need tweaking in the future.
    else:
        cur_path = os.path.dirname(os.path.realpath(__file__))
        path = os.path.join(cur_path, '..', SDK_INTEGRATIONS_DIR)

    if os.path.exists(path):
        return path
    raise PathNotFound(path)
开发者ID:ross,项目名称:dd-agent,代码行数:24,代码来源:config.py


示例16: load_check_directory

def load_check_directory(agentConfig, hostname):
    ''' Return the initialized checks from checks.d, and a mapping of checks that failed to
    initialize. Only checks that have a configuration
    file in conf.d will be returned. '''
    from checks import AGENT_METRICS_CHECK_NAME

    initialized_checks = {}
    init_failed_checks = {}
    deprecated_checks = {}
    agentConfig['checksd_hostname'] = hostname
    osname = get_os()

    # the TRACE_CONFIG flag is used by the configcheck to trace config object loading and
    # where they come from (service discovery, auto config or config file)
    if agentConfig.get(TRACE_CONFIG):
        configs_and_sources = {
            # check_name: (config_source, config)
        }

    deprecated_checks.update(_deprecated_configs(agentConfig))

    checks_places = get_checks_places(osname, agentConfig)

    for config_path in _file_configs_paths(osname, agentConfig):
        # '/etc/dd-agent/checks.d/my_check.py' -> 'my_check'
        check_name = _conf_path_to_check_name(config_path)

        conf_is_valid, check_config, invalid_check = _load_file_config(config_path, check_name, agentConfig)
        init_failed_checks.update(invalid_check)
        if not conf_is_valid:
            continue

        if agentConfig.get(TRACE_CONFIG):
            configs_and_sources[check_name] = (CONFIG_FROM_FILE, check_config)

        # load the check
        load_success, load_failure = load_check_from_places(check_config, check_name, checks_places, agentConfig)

        initialized_checks.update(load_success)
        init_failed_checks.update(load_failure)

    for check_name, service_disco_check_config in _service_disco_configs(agentConfig).iteritems():
        # ignore this config from service disco if the check has been loaded through a file config
        if check_name in initialized_checks or check_name in init_failed_checks:
            continue

        # if TRACE_CONFIG is set, service_disco_check_config looks like:
        # (config_src, (sd_init_config, sd_instances)) instead of
        # (sd_init_config, sd_instances)
        if agentConfig.get(TRACE_CONFIG):
            sd_init_config, sd_instances = service_disco_check_config[1]
            configs_and_sources[check_name] = (
                service_disco_check_config[0],
                {'init_config': sd_init_config, 'instances': sd_instances})
        else:
            sd_init_config, sd_instances = service_disco_check_config

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

        # load the check
        load_success, load_failure = load_check_from_places(check_config, check_name, checks_places, agentConfig)

        initialized_checks.update(load_success)
        init_failed_checks.update(load_failure)

    init_failed_checks.update(deprecated_checks)
    log.info('initialized checks.d checks: %s' % [k for k in initialized_checks.keys() if k != AGENT_METRICS_CHECK_NAME])
    log.info('initialization failed checks.d checks: %s' % init_failed_checks.keys())

    if agentConfig.get(TRACE_CONFIG):
        return configs_and_sources

    return {'initialized_checks': initialized_checks.values(),
            'init_failed_checks': init_failed_checks,
            }
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:75,代码来源:config.py


示例17: initialize_logging

def initialize_logging(logger_name):
    try:
        logging_config = get_logging_config()

        logging.basicConfig(
            format=get_log_format(logger_name),
            level=logging_config['log_level'] or logging.INFO,
        )

        log_file = logging_config.get('%s_log_file' % logger_name)
        if log_file is not None and not logging_config['disable_file_logging']:
            # make sure the log directory is writeable
            # NOTE: the entire directory needs to be writable so that rotation works
            if os.access(os.path.dirname(log_file), os.R_OK | os.W_OK):
                file_handler = logging.handlers.RotatingFileHandler(log_file, maxBytes=LOGGING_MAX_BYTES, backupCount=1)
                formatter = logging.Formatter(get_log_format(logger_name), get_log_date_format())
                file_handler.setFormatter(formatter)

                root_log = logging.getLogger()
                root_log.addHandler(file_handler)
            else:
                sys.stderr.write("Log file is unwritable: '%s'\n" % log_file)

        # set up syslog
        if logging_config['log_to_syslog']:
            try:
                from logging.handlers import SysLogHandler

                if logging_config['syslog_host'] is not None and logging_config['syslog_port'] is not None:
                    sys_log_addr = (logging_config['syslog_host'], logging_config['syslog_port'])
                else:
                    sys_log_addr = "/dev/log"
                    # Special-case BSDs
                    if Platform.is_darwin():
                        sys_log_addr = "/var/run/syslog"
                    elif Platform.is_freebsd():
                        sys_log_addr = "/var/run/log"

                handler = SysLogHandler(address=sys_log_addr, facility=SysLogHandler.LOG_DAEMON)
                handler.setFormatter(logging.Formatter(get_syslog_format(logger_name), get_log_date_format()))
                root_log = logging.getLogger()
                root_log.addHandler(handler)
            except Exception as e:
                sys.stderr.write("Error setting up syslog: '%s'\n" % str(e))
                traceback.print_exc()

        # Setting up logging in the event viewer for windows
        if get_os() == 'windows' and logging_config['log_to_event_viewer']:
            try:
                from logging.handlers import NTEventLogHandler
                nt_event_handler = NTEventLogHandler(logger_name, get_win32service_file('windows', 'win32service.pyd'), 'Application')
                nt_event_handler.setFormatter(logging.Formatter(get_syslog_format(logger_name), get_log_date_format()))
                nt_event_handler.setLevel(logging.ERROR)
                app_log = logging.getLogger(logger_name)
                app_log.addHandler(nt_event_handler)
            except Exception as e:
                sys.stderr.write("Error setting up Event viewer logging: '%s'\n" % str(e))
                traceback.print_exc()

    except Exception as e:
        sys.stderr.write("Couldn't initialize logging: %s\n" % str(e))
        traceback.print_exc()

        # if config fails entirely, enable basic stdout logging as a fallback
        logging.basicConfig(
            format=get_log_format(logger_name),
            level=logging.INFO,
        )

    # re-get the log after logging is initialized
    global log
    log = logging.getLogger(__name__)
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:72,代码来源:config.py


示例18: __init__

    def __init__(self, agentConfig, emitters, systemStats, hostname):
        self.emit_duration = None
        self.agentConfig = agentConfig
        self.hostname = hostname
        # system stats is generated by config.get_system_stats
        self.agentConfig['system_stats'] = systemStats
        # agent config is used during checks, system_stats can be accessed through the config
        self.os = get_os()
        self.plugins = None
        self.emitters = emitters
        self.check_timings = agentConfig.get('check_timings')
        self.push_times = {
            'host_metadata': {
                'start': time.time(),
                'interval': int(agentConfig.get('metadata_interval', 4 * 60 * 60))
            },
            'external_host_tags': {
                'start': time.time() - 3 * 60,  # Wait for the checks to init
                'interval': int(agentConfig.get('external_host_tags', 5 * 60))
            },
            'agent_checks': {
                'start': time.time(),
                'interval': int(agentConfig.get('agent_checks_interval', 10 * 60))
            },
            'processes': {
                'start': time.time(),
                'interval': int(agentConfig.get('processes_interval', 60))
            }
        }
        socket.setdefaulttimeout(15)
        self.run_count = 0
        self.continue_running = True
        self.hostname_metadata_cache = None
        self.initialized_checks_d = []
        self.init_failed_checks_d = {}

        if Platform.is_linux() and psutil is not None:
            procfs_path = agentConfig.get('procfs_path', '/proc').rstrip('/')
            psutil.PROCFS_PATH = procfs_path

        # Unix System Checks
        self._unix_system_checks = {
            'io': u.IO(log),
            'load': u.Load(log),
            'memory': u.Memory(log),
            'processes': u.Processes(log),
            'cpu': u.Cpu(log),
            'system': u.System(log)
        }

        # Win32 System `Checks
        self._win32_system_checks = {
            'io': w32.IO(log),
            'proc': w32.Processes(log),
            'memory': w32.Memory(log),
            'network': w32.Network(log),
            'cpu': w32.Cpu(log),
            'system': w32.System(log)
        }

        # Old-style metric checks
        self._ganglia = Ganglia(log) if self.agentConfig.get('ganglia_host', '') != '' else None
        self._dogstream = None if self.agentConfig.get('dogstreams') is None else Dogstreams.init(log, self.agentConfig)

        # Agent performance metrics check
        self._agent_metrics = None

        self._metrics_checks = []

        # Custom metric checks
        for module_spec in [s.strip() for s in self.agentConfig.get('custom_checks', '').split(',')]:
            if len(module_spec) == 0:
                continue
            try:
                self._metrics_checks.append(modules.load(module_spec, 'Check')(log))
                log.info("Registered custom check %s" % module_spec)
                log.warning("Old format custom checks are deprecated. They should be moved to the checks.d interface as old custom checks will be removed in a next version")
            except Exception:
                log.exception('Unable to load custom check module %s' % module_spec)
开发者ID:motusllc,项目名称:dd-agent,代码行数:79,代码来源:collector.py


示例19: get_config

def get_config(parse_args=True, cfg_path=None, options=None):
    if parse_args:
        options, _ = get_parsed_args()

    # General config
    agentConfig = {
        'check_freq': DEFAULT_CHECK_FREQUENCY,
        'dogstatsd_port': 8125,
        'dogstatsd_target': 'http://localhost:17123',
        'graphite_listen_port': None,
        'hostname': None,
        'listen_port': None,
        'tags': None,
        'use_ec2_instance_id': False,  # DEPRECATED
        'version': get_version(),
        'watchdog': True,
        'additional_checksd': '/etc/dd-agent/checks.d/',
        'bind_host': get_default_bind_host(),
        'statsd_metric_namespace': None,
        'utf8_decoding': False
    }

    if Platform.is_mac():
        agentConfig['additional_checksd'] = '/opt/datadog-agent/etc/checks.d'

    # Config handling
    try:
        # Find the right config file
        path = os.path.realpath(__file__)
        path = os.path.dirname(path)

        config_path = get_config_path(cfg_path, os_name=get_os())
        config = ConfigParser.ConfigParser()
        config.readfp(skip_leading_wsp(open(config_path)))

        # bulk import
        for option in config.options('Main'):
            agentConfig[option] = config.get('Main', option)

        # Store developer mode setting in the agentConfig
        if config.has_option('Main', 'developer_mode'):
            agentConfig['developer_mode'] = _is_affirmative(config.get('Main', 'developer_mode'))

        # Allow an override with the --profile option
        if options is not None and options.profile:
            agentConfig['developer_mode'] = True

        #
        # Core config
        #ap
        if not config.has_option('Main', 'api_key'):
            log.warning(u"No API key was found. Aborting.")
            sys.exit(2)

        if not config.has_option('Main', 'dd_url'):
            log.warning(u"No dd_url was found. Aborting.")
            sys.exit(2)

        # Endpoints
        dd_urls = map(clean_dd_url, config.get('Main', 'dd_url').split(','))
        api_keys = map(lambda el: el.strip(), config.get('Main', 'api_key').split(','))

        # For collector and dogstatsd
        agentConfig['dd_url'] = dd_urls[0]
        agentConfig['api_key'] = api_keys[0]

        # Forwarder endpoints logic
        # endpoints is:
        # {
        #    'https://app.datadoghq.com': ['api_key_abc', 'api_key_def'],
        #    'https://app.example.com': ['api_key_xyz']
        # }
        endpoints = {}
        dd_urls = remove_empty(dd_urls)
        api_keys = remove_empty(api_keys)
        if len(dd_urls) == 1:
            if len(api_keys) > 0:
                endpoints[dd_urls[0]] = api_keys
        else:
            assert len(dd_urls) == len(api_keys), 'Please provide one api_key for each url'
            for i, dd_url in enumerate(dd_urls):
                endpoints[dd_url] = endpoints.get(dd_url, []) + [api_keys[i]]

        agentConfig['endpoints'] = endpoints

        # Forwarder or not forwarder
        agentConfig['use_forwarder'] = options is not None and options.use_forwarder
        if agentConfig['use_forwarder']:
            listen_port = 17123
            if config.has_option('Main', 'listen_port'):
                listen_port = int(config.get('Main', 'listen_port'))
            agentConfig['dd_url'] = "http://{}:{}".format(agentConfig['bind_host'], listen_port)
        # FIXME: Legacy dd_url command line switch
        elif options is not None and options.dd_url is not None:
            agentConfig['dd_url'] = options.dd_url

        # Forwarder timeout
        agentConfig['forwarder_timeout'] = 20
        if config.has_option('Main', 'forwarder_timeout'):
            agentConfig['forwarder_timeout'] = int(config.get('Main', 'forwarder_timeout'))
#.........这里部分代码省略.........
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:101,代码来源:config.py


示例20: get_log_format

def get_log_format(logger_name):
    if get_os() != 'windows':
        return '%%(asctime)s | %%(levelname)s | dd.%s | %%(name)s(%%(filename)s:%%(lineno)s) | %%(message)s' % logger_name
    return '%(asctime)s | %(levelname)s | %(name)s(%(filename)s:%(lineno)s) | %(message)s'
开发者ID:ewdurbin,项目名称:dd-agent,代码行数:4,代码来源:config.py



注:本文中的utils.platform.get_os函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python platform.Platform类代码示例发布时间:2022-05-26
下一篇:
Python pkl_utils._load函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap