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


Python Platform.is_freebsd方法代码示例

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


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

示例1: get_system_stats

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_freebsd [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: get_system_stats

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_freebsd [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

示例3: parse_df_output

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_freebsd [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

示例4: _check_bsd

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_freebsd [as 别名]
    def _check_bsd(self, instance):
        netstat_flags = ['-i', '-b']

        # FreeBSD's netstat truncates device names unless you pass '-W'
        if Platform.is_freebsd():
            netstat_flags.append('-W')

        netstat = subprocess.Popen(["netstat"] + netstat_flags,
                                   stdout=subprocess.PIPE,
                                   close_fds=True).communicate()[0]
        # Name  Mtu   Network       Address            Ipkts Ierrs     Ibytes    Opkts Oerrs     Obytes  Coll
        # lo0   16384 <Link#1>                        318258     0  428252203   318258     0  428252203     0
        # lo0   16384 localhost   fe80:1::1           318258     -  428252203   318258     -  428252203     -
        # lo0   16384 127           localhost         318258     -  428252203   318258     -  428252203     -
        # lo0   16384 localhost   ::1                 318258     -  428252203   318258     -  428252203     -
        # gif0* 1280  <Link#2>                             0     0          0        0     0          0     0
        # stf0* 1280  <Link#3>                             0     0          0        0     0          0     0
        # en0   1500  <Link#4>    04:0c:ce:db:4e:fa 20801309     0 13835457425 15149389     0 11508790198     0
        # en0   1500  seneca.loca fe80:4::60c:ceff: 20801309     - 13835457425 15149389     - 11508790198     -
        # en0   1500  2001:470:1f 2001:470:1f07:11d 20801309     - 13835457425 15149389     - 11508790198     -
        # en0   1500  2001:470:1f 2001:470:1f07:11d 20801309     - 13835457425 15149389     - 11508790198     -
        # en0   1500  192.168.1     192.168.1.63    20801309     - 13835457425 15149389     - 11508790198     -
        # en0   1500  2001:470:1f 2001:470:1f07:11d 20801309     - 13835457425 15149389     - 11508790198     -
        # p2p0  2304  <Link#5>    06:0c:ce:db:4e:fa        0     0          0        0     0          0     0
        # ham0  1404  <Link#6>    7a:79:05:4d:bf:f5    30100     0    6815204    18742     0    8494811     0
        # ham0  1404  5             5.77.191.245       30100     -    6815204    18742     -    8494811     -
        # ham0  1404  seneca.loca fe80:6::7879:5ff:    30100     -    6815204    18742     -    8494811     -
        # ham0  1404  2620:9b::54 2620:9b::54d:bff5    30100     -    6815204    18742     -    8494811     -

        lines = netstat.split("\n")
        headers = lines[0].split()

        # Given the irregular structure of the table above, better to parse from the end of each line
        # Verify headers first
        #          -7       -6       -5        -4       -3       -2        -1
        for h in ("Ipkts", "Ierrs", "Ibytes", "Opkts", "Oerrs", "Obytes", "Coll"):
            if h not in headers:
                self.logger.error("%s not found in %s; cannot parse" % (h, headers))
                return False

        current = None
        for l in lines[1:]:
            # Another header row, abort now, this is IPv6 land
            if "Name" in l:
                break

            x = l.split()
            if len(x) == 0:
                break

            iface = x[0]
            if iface.endswith("*"):
                iface = iface[:-1]
            if iface == current:
                # skip multiple lines of same interface
                continue
            else:
                current = iface

            # Filter inactive interfaces
            if self._parse_value(x[-5]) or self._parse_value(x[-2]):
                iface = current
                metrics = {
                    'bytes_rcvd': self._parse_value(x[-5]),
                    'bytes_sent': self._parse_value(x[-2]),
                    'packets_in.count': self._parse_value(x[-7]),
                    'packets_in.error': self._parse_value(x[-6]),
                    'packets_out.count': self._parse_value(x[-4]),
                    'packets_out.error':self._parse_value(x[-3]),
                }
                self._submit_devicemetrics(iface, metrics)


        netstat = subprocess.Popen(["netstat", "-s","-p" "tcp"],
                                   stdout=subprocess.PIPE,
                                   close_fds=True).communicate()[0]
        #3651535 packets sent
        #        972097 data packets (615753248 bytes)
        #        5009 data packets (2832232 bytes) retransmitted
        #        0 resends initiated by MTU discovery
        #        2086952 ack-only packets (471 delayed)
        #        0 URG only packets
        #        0 window probe packets
        #        310851 window update packets
        #        336829 control packets
        #        0 data packets sent after flow control
        #        3058232 checksummed in software
        #        3058232 segments (571218834 bytes) over IPv4
        #        0 segments (0 bytes) over IPv6
        #4807551 packets received
        #        1143534 acks (for 616095538 bytes)
        #        165400 duplicate acks
        #        ...

        self._submit_regexed_values(netstat, BSD_TCP_METRICS)
开发者ID:AquaBindi,项目名称:dd-agent,代码行数:97,代码来源:network.py


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