当前位置: 首页>>代码示例>>Python>>正文


Python Platform.is_unix方法代码示例

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


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

示例1: _init_permissions_file

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
 def _init_permissions_file(self):
     self._permissions_file = tempfile.NamedTemporaryFile(mode='w', prefix='dd', delete=False)
     if Platform.is_unix():
         self._permissions_file_format = "{0:50} | {1:5} | {2:10} | {3:10}\n"
         header = self._permissions_file_format.format("File path", "mode", "owner", "group")
         self._permissions_file.write(header)
         self._permissions_file.write('-'*len(header) + "\n")
     else:
         self._permissions_file.write("Not implemented: file permissions are only logged on Unix platforms")
开发者ID:jimmystewpot,项目名称:dd-agent,代码行数:11,代码来源:flare.py

示例2: check_user_rights

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
 def check_user_rights():
     if Platform.is_unix() and not os.geteuid() == 0:
         log.warning("You are not root, some information won't be collected")
         choice = raw_input('Are you sure you want to continue [y/N]? ')
         if choice.strip().lower() not in ['yes', 'y']:
             print 'Aborting'
             sys.exit(1)
         else:
             log.warn('Your user has to have at least read access'
                      ' to the logs and conf files of the agent')
开发者ID:Shopify,项目名称:dd-agent,代码行数:12,代码来源:flare.py

示例3: _add_file_tar

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
    def _add_file_tar(self, file_path, target_path, log_permissions=True, original_file_path=None):
        target_full_path = os.path.join(self._prefix, target_path)
        if log_permissions and Platform.is_unix():
            stat_file_path = original_file_path or file_path
            file_stat = os.stat(stat_file_path)
            # The file mode is returned in binary format, convert it to a more readable octal string
            mode = oct(stat.S_IMODE(file_stat.st_mode))
            try:
                uname = pwd.getpwuid(file_stat.st_uid).pw_name
            except KeyError:
                uname = str(file_stat.st_uid)
            try:
                gname = grp.getgrgid(file_stat.st_gid).gr_name
            except KeyError:
                gname = str(file_stat.st_gid)
            self._permissions_file.write(self._permissions_file_format.format(stat_file_path, mode, uname, gname))

        self._tar.add(file_path, target_full_path)
开发者ID:jimmystewpot,项目名称:dd-agent,代码行数:20,代码来源:flare.py

示例4: psutil_wrapper

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
    def psutil_wrapper(self, process, method, accessors, *args, **kwargs):
        """
        A psutil wrapper that is calling
        * psutil.method(*args, **kwargs) and returns the result
        OR
        * psutil.method(*args, **kwargs).accessor[i] for each accessors given in
        a list, the result being indexed in a dictionary by the accessor name
        """

        if accessors is None:
            result = None
        else:
            result = {}

        # Ban certain method that we know fail
        if method == 'memory_info_ex'\
                and (Platform.is_win32() or Platform.is_solaris()):
            return result
        elif method == 'num_fds' and not Platform.is_unix():
            return result
        elif method == 'num_handles' and not Platform.is_win32():
            return result

        try:
            res = getattr(process, method)(*args, **kwargs)
            if accessors is None:
                result = res
            else:
                for acc in accessors:
                    try:
                        result[acc] = getattr(res, acc)
                    except AttributeError:
                        self.log.debug("psutil.%s().%s attribute does not exist", method, acc)
        except (NotImplementedError, AttributeError):
            self.log.debug("psutil method %s not implemented", method)
        except psutil.AccessDenied:
            self.log.debug("psutil was denied acccess for method %s", method)
        ## we don't want this warning output
        # except psutil.NoSuchProcess:
            # self.warning("Process {0} disappeared while scanning".format(process.pid))

        return result
开发者ID:tomazstrukeljdlabs,项目名称:ansible-datadog,代码行数:44,代码来源:process.py

示例5: get_hostname

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
def get_hostname(config=None):
    """
    Get the canonical host name this agent should identify as. This is
    the authoritative source of the host name for the agent.

    Tries, in order:

      * agent config (datadog.conf, "hostname:")
      * 'hostname -f' (on unix)
      * socket.gethostname()
    """
    hostname = None

    # first, try the config
    if config is None:
        from config import get_config
        config = get_config(parse_args=True)
    config_hostname = config.get('hostname')
    if config_hostname and is_valid_hostname(config_hostname):
        return config_hostname

    # Try to get GCE instance name
    gce_hostname = GCE.get_hostname(config)
    if gce_hostname is not None:
        if is_valid_hostname(gce_hostname):
            return gce_hostname

    # Try to get the docker hostname
    if Platform.is_containerized():

        # First we try from the Docker API
        docker_util = DockerUtil()
        docker_hostname = docker_util.get_hostname(use_default_gw=False)
        if docker_hostname is not None and is_valid_hostname(docker_hostname):
            hostname = docker_hostname

        elif Platform.is_k8s(): # Let's try from the kubelet
            kube_util = KubeUtil()
            _, kube_hostname = kube_util.get_node_info()
            if kube_hostname is not None and is_valid_hostname(kube_hostname):
                hostname = kube_hostname

    # then move on to os-specific detection
    if hostname is None:
        if Platform.is_unix() or Platform.is_solaris():
            unix_hostname = _get_hostname_unix()
            if unix_hostname and is_valid_hostname(unix_hostname):
                hostname = unix_hostname

    # if we have an ec2 default hostname, see if there's an instance-id available
    if (Platform.is_ecs_instance()) or (hostname is not None and EC2.is_default(hostname)):
        instanceid = EC2.get_instance_id(config)
        if instanceid:
            hostname = instanceid

    # fall back on socket.gethostname(), socket.getfqdn() is too unreliable
    if hostname is None:
        try:
            socket_hostname = socket.gethostname()
        except socket.error:
            socket_hostname = None
        if socket_hostname and is_valid_hostname(socket_hostname):
            hostname = socket_hostname

    if hostname is None:
        log.critical('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
        raise Exception('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')

    return hostname
开发者ID:Everlane,项目名称:dd-agent,代码行数:71,代码来源:hostname.py

示例6:

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
from utils.platform import Platform

if Platform.is_mac():
    CHECK_RATES = [
        'system.core.idle',
        'system.core.nice',
        'system.core.system',
        'system.core.user',
    ]
    MOCK_PSUTIL_CPU_TIMES = [
        psutil._psosx.scputimes(user=7877.29, nice=0.0, system=7469.72, idle=38164.81),
        psutil._psosx.scputimes(user=3826.74, nice=0.0, system=2701.6, idle=46981.39),
        psutil._psosx.scputimes(user=7486.51, nice=0.0, system=5991.36, idle=40031.88),
        psutil._psosx.scputimes(user=3964.85, nice=0.0, system=2862.37, idle=46682.5)
    ]
elif Platform.is_unix():
    CHECK_RATES = [
        'system.core.idle',
        'system.core.nice',
        'system.core.system',
        'system.core.user',
        'system.core.iowait',
        'system.core.irq',
        'system.core.softirq',
        'system.core.steal',
        'system.core.guest',
        'system.core.guest_nice',
    ]
    MOCK_PSUTIL_CPU_TIMES = [
        psutil._pslinux.scputimes(user=1805.64, nice=0.01, system=298.66, idle=14177.28,
                                  iowait=3.23, irq=0.05, softirq=33.28, steal=0.0,
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:33,代码来源:test_system_core.py

示例7: get_hostname

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_unix [as 别名]
 
 # project
 from utils.cloud_metadata import EC2, GCE
-from utils.dockerutil import DockerUtil
-from utils.kubeutil import KubeUtil
 from utils.platform import Platform
 from utils.subprocess_output import get_subprocess_output
 
@@ -72,21 +70,6 @@ def get_hostname(config=None):
         if is_valid_hostname(gce_hostname):
             return gce_hostname
 
-    # Try to get the docker hostname
-    if Platform.is_containerized():
-
-        # First we try from the Docker API
-        docker_util = DockerUtil()
-        docker_hostname = docker_util.get_hostname(use_default_gw=False)
-        if docker_hostname is not None and is_valid_hostname(docker_hostname):
-            hostname = docker_hostname
-
-        elif Platform.is_k8s(): # Let's try from the kubelet
-            kube_util = KubeUtil()
-            _, kube_hostname = kube_util.get_node_info()
-            if kube_hostname is not None and is_valid_hostname(kube_hostname):
-                hostname = kube_hostname
-
     # then move on to os-specific detection
     if hostname is None:
         if Platform.is_unix() or Platform.is_solaris():
开发者ID:urosgruber,项目名称:dd-agent-FreeBSD,代码行数:32,代码来源:patch-utils_hostname.py


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