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


Python Platform.is_darwin方法代码示例

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


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

示例1: get_system_stats

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
def get_system_stats():
    systemStats = {
        'machine': platform.machine(),
        'platform': sys.platform,
        'processor': platform.processor(),
        'pythonV': platform.python_version(),
    }

    platf = sys.platform
    
    if  Platform.is_linux(platf):
        grep = subprocess.Popen(['grep', 'model name', '/proc/cpuinfo'], stdout=subprocess.PIPE, close_fds=True)
        wc = subprocess.Popen(['wc', '-l'], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
        systemStats['cpuCores'] = int(wc.communicate()[0])

    if Platform.is_darwin(platf):
        systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])

    if Platform.is_freebsd(platf):
        systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])

    if Platform.is_linux(platf):
        systemStats['nixV'] = platform.dist()

    elif Platform.is_darwin(platf):
        systemStats['macV'] = platform.mac_ver()

    elif Platform.is_freebsd(platf):
        version = platform.uname()[2]
        systemStats['fbsdV'] = ('freebsd', version, '')  # no codename for FreeBSD

    elif Platform.is_win32(platf):
        systemStats['winV'] = platform.win32_ver()

    return systemStats
开发者ID:ghessler,项目名称:dd-agent,代码行数:37,代码来源:config.py

示例2: _host_matches_node

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
    def _host_matches_node(self, primary_addrs):
        """ For < 0.19, check if the current host matches the IP given in the
            cluster nodes check `/_cluster/nodes`. Uses `ip addr` on Linux and
            `ifconfig` on Mac
        """
        if Platform.is_darwin():
            ifaces = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE)
        else:
            ifaces = subprocess.Popen(["ip", "addr"], stdout=subprocess.PIPE)
        grepper = subprocess.Popen(
            ["grep", "inet"], stdin=ifaces.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE
        )

        ifaces.stdout.close()
        out, err = grepper.communicate()

        # Capture the list of interface IPs
        ips = []
        for iface in out.split("\n"):
            iface = iface.strip()
            if iface:
                ips.append(iface.split(" ")[1].split("/")[0])

        # Check the interface addresses against the primary address
        return primary_addrs in ips
开发者ID:jonathonwiebe,项目名称:dd-agent,代码行数:27,代码来源:elastic.py

示例3: get_system_stats

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
def get_system_stats():
    systemStats = {
        "machine": platform.machine(),
        "platform": sys.platform,
        "processor": platform.processor(),
        "pythonV": platform.python_version(),
    }

    platf = sys.platform

    if Platform.is_linux(platf):
        grep = subprocess.Popen(["grep", "model name", "/proc/cpuinfo"], stdout=subprocess.PIPE, close_fds=True)
        wc = subprocess.Popen(["wc", "-l"], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
        systemStats["cpuCores"] = int(wc.communicate()[0])

    if Platform.is_darwin(platf):
        systemStats["cpuCores"] = int(
            subprocess.Popen(["sysctl", "hw.ncpu"], stdout=subprocess.PIPE, close_fds=True)
            .communicate()[0]
            .split(": ")[1]
        )

    if Platform.is_freebsd(platf):
        systemStats["cpuCores"] = int(
            subprocess.Popen(["sysctl", "hw.ncpu"], stdout=subprocess.PIPE, close_fds=True)
            .communicate()[0]
            .split(": ")[1]
        )

    if Platform.is_linux(platf):
        systemStats["nixV"] = platform.dist()

    elif Platform.is_darwin(platf):
        systemStats["macV"] = platform.mac_ver()

    elif Platform.is_freebsd(platf):
        version = platform.uname()[2]
        systemStats["fbsdV"] = ("freebsd", version, "")  # no codename for FreeBSD

    elif Platform.is_win32(platf):
        systemStats["winV"] = platform.win32_ver()

    return systemStats
开发者ID:kzw,项目名称:dd-agent,代码行数:45,代码来源:config.py

示例4: parse_df_output

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_darwin [as 别名]
    def parse_df_output(self, df_output, platform_name, inodes=False, use_mount=False, blacklist_re=None):
        """
        Parse the output of the df command. If use_volume is true the volume
        is used to anchor the metric, otherwise false the mount 
        point is used. Returns a tuple of (disk, inode).
        """
        usage_data = []

        # Transform the raw output into tuples of the df data.
        devices = self._transform_df_output(df_output, blacklist_re)

        # If we want to use the mount point, replace the volume name on each
        # line.
        for parts in devices:
            try:
                if use_mount:
                    parts[0] = parts[-1]
                if inodes:
                    if Platform.is_darwin(platform_name):
                        # Filesystem 512-blocks Used Available Capacity iused ifree %iused  Mounted
                        # Inodes are in position 5, 6 and we need to compute the total
                        # Total
                        parts[1] = int(parts[5]) + int(parts[6]) # Total
                        parts[2] = int(parts[5]) # Used
                        parts[3] = int(parts[6]) # Available
                    elif Platform.is_freebsd(platform_name):
                        # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted
                        # Inodes are in position 5, 6 and we need to compute the total
                        parts[1] = int(parts[5]) + int(parts[6]) # Total
                        parts[2] = int(parts[5]) # Used
                        parts[3] = int(parts[6]) # Available
                    else:
                        parts[1] = int(parts[1]) # Total
                        parts[2] = int(parts[2]) # Used
                        parts[3] = int(parts[3]) # Available
                else:
                    parts[1] = int(parts[1]) # Total
                    parts[2] = int(parts[2]) # Used
                    parts[3] = int(parts[3]) # Available
            except IndexError:
                self.logger.exception("Cannot parse %s" % (parts,))

            usage_data.append(parts)

        return usage_data
开发者ID:AirbornePorcine,项目名称:dd-agent,代码行数:47,代码来源:unix.py


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