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


Python util.Platform类代码示例

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


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

示例1: testNetwork

    def testNetwork(self):
        # FIXME: cx_state to true, but needs sysstat installed
        config = """
init_config:

instances:
    - collect_connection_state: false
      excluded_interfaces:
        - lo
        - lo0
"""
        check, instances = get_check("network", config)

        check.check(instances[0])
        check.get_metrics()

        metric_names = [m[0] for m in check.aggregator.metrics]

        assert "system.net.bytes_rcvd" in metric_names
        assert "system.net.bytes_sent" in metric_names
        if Platform.is_linux():
            assert "system.net.tcp.retrans_segs" in metric_names
            assert "system.net.tcp.in_segs" in metric_names
            assert "system.net.tcp.out_segs" in metric_names
        elif Platform.is_bsd():
            assert "system.net.tcp.retrans_packs" in metric_names
            assert "system.net.tcp.sent_packs" in metric_names
            assert "system.net.tcp.rcv_packs" in metric_names
开发者ID:miketheman,项目名称:dd-agent,代码行数:28,代码来源:test_system.py

示例2: collect_metrics_psutil

    def collect_metrics_psutil(self):
        self._valid_disks = {}
        for part in psutil.disk_partitions(all=True):
            # we check all exclude conditions
            if self._exclude_disk_psutil(part):
                continue

            # Get disk metrics here to be able to exclude on total usage
            try:
                disk_usage = timeout(5)(psutil.disk_usage)(part.mountpoint)
            except TimeoutException:
                self.log.warn(
                    u"Timeout while retrieving the disk usage of `%s` mountpoint. Skipping...",
                    part.mountpoint
                )
                continue
            except Exception as e:
                self.log.warn("Unable to get disk metrics for %s: %s", part.mountpoint, e)
                continue
            # Exclude disks with total disk size 0
            if disk_usage.total == 0:
                continue
            # For later, latency metrics
            self._valid_disks[part.device] = (part.fstype, part.mountpoint)
            self.log.debug('Passed: {0}'.format(part.device))

            tags = [part.fstype] if self._tag_by_filesystem else []
            device_name = part.mountpoint if self._use_mount else part.device

            # Note: psutil (0.3.0 to at least 3.1.1) calculates in_use as (used / total)
            #       The problem here is that total includes reserved space the user
            #       doesn't have access to. This causes psutil to calculate a misleadng
            #       percentage for in_use; a lower percentage than df shows.

            # Calculate in_use w/o reserved space; consistent w/ df's Use% metric.
            pmets = self._collect_part_metrics(part, disk_usage)
            used = 'system.disk.used'
            free = 'system.disk.free'
            pmets['system.disk.in_use'] = pmets[used] / (pmets[used] + pmets[free])

            # legacy check names c: vs psutil name C:\\
            if Platform.is_win32():
                device_name = device_name.strip('\\').lower()
            for metric_name, metric_value in pmets.iteritems():
                self.gauge(metric_name, metric_value,
                           tags=tags, device_name=device_name)
        # And finally, latency metrics, a legacy gift from the old Windows Check
        if Platform.is_win32():
            self.collect_latency_metrics()
开发者ID:AltSchool,项目名称:dd-agent,代码行数:49,代码来源:disk.py

示例3: testMemory

 def testMemory(self):
     global logger
     res = Memory(logger).check({})
     if Platform.is_linux():
         MEM_METRICS = [
             "swapTotal",
             "swapFree",
             "swapPctFree",
             "swapUsed",
             "physTotal",
             "physFree",
             "physUsed",
             "physBuffers",
             "physCached",
             "physUsable",
             "physPctUsable",
             "physShared",
         ]
         for k in MEM_METRICS:
             # % metric is only here if total > 0
             if k == "swapPctFree" and res["swapTotal"] == 0:
                 continue
             assert k in res, res
         assert res["swapTotal"] == res["swapFree"] + res["swapUsed"]
         assert res["physTotal"] == res["physFree"] + res["physUsed"]
     elif sys.platform == "darwin":
         for k in ("swapFree", "swapUsed", "physFree", "physUsed"):
             assert k in res, res
开发者ID:miketheman,项目名称:dd-agent,代码行数:28,代码来源:test_system.py

示例4: collect_metrics_psutil

    def collect_metrics_psutil(self):
        self._valid_disks = {}
        for part in psutil.disk_partitions(all=True):
            # we check all exclude conditions
            if self._exclude_disk_psutil(part):
                continue
            # Get disk metrics here to be able to exclude on total usage
            try:
                disk_usage = psutil.disk_usage(part.mountpoint)
            except Exception, e:
                self.log.debug("Unable to get disk metrics for %s: %s",
                               part.mountpoint, e)
                continue
            # Exclude disks with total disk size 0
            if disk_usage.total == 0:
                continue
            # For later, latency metrics
            self._valid_disks[part.device] = (part.fstype, part.mountpoint)
            self.log.debug('Passed: {0}'.format(part.device))

            tags = [part.fstype] if self._tag_by_filesystem else []
            device_name = part.mountpoint if self._use_mount else part.device

            # legacy check names c: vs psutil name C:\\
            if Platform.is_win32():
                device_name = device_name.strip('\\').lower()
            for metric_name, metric_value in self._collect_part_metrics(part, disk_usage).iteritems():
                self.gauge(metric_name, metric_value,
                           tags=tags, device_name=device_name)
开发者ID:Shopify,项目名称:dd-agent,代码行数:29,代码来源:disk.py

示例5: check

    def check(self, instance):
        """ Collect metrics for the given gunicorn instance. """
        self.log.debug("Running instance: %s", instance)

        if Platform.is_linux():
            procfs_path = self.agentConfig.get('procfs_path', '/proc').rstrip('/')
            psutil.PROCFS_PATH = procfs_path

        # Validate the config.
        if not instance or self.PROC_NAME not in instance:
            raise GUnicornCheckError("instance must specify: %s" % self.PROC_NAME)

        # Load the gunicorn master procedure.
        proc_name = instance.get(self.PROC_NAME)
        master_proc = self._get_master_proc_by_name(proc_name)

        # Fetch the worker procs and count their states.
        worker_procs = master_proc.children()
        working, idle = self._count_workers(worker_procs)

        # if no workers are running, alert CRITICAL, otherwise OK
        msg = "%s working and %s idle workers for %s" % (working, idle, proc_name)
        status = AgentCheck.CRITICAL if working == 0 and idle == 0 else AgentCheck.OK

        self.service_check(self.SVC_NAME, status, tags=['app:' + proc_name], message=msg)

        # Submit the data.
        self.log.debug("instance %s procs - working:%s idle:%s" % (proc_name, working, idle))
        self.gauge("gunicorn.workers", working, self.WORKING_TAGS)
        self.gauge("gunicorn.workers", idle, self.IDLE_TAGS)
开发者ID:AltSchool,项目名称:dd-agent,代码行数:30,代码来源:gunicorn.py

示例6: _host_matches_node

    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,代码行数:25,代码来源:elastic.py

示例7: _exclude_disk_psutil

 def _exclude_disk_psutil(self, part):
     # skip cd-rom drives with no disk in it; they may raise
     # ENOENT, pop-up a Windows GUI error for a non-ready
     # partition or just hang;
     # and all the other excluded disks
     return ((Platform.is_win32() and ('cdrom' in part.opts or
                                       part.fstype == '')) or
             self._exclude_disk(part.device, part.fstype, part.mountpoint))
开发者ID:AltSchool,项目名称:dd-agent,代码行数:8,代码来源:disk.py

示例8: parse_df_output

    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,代码行数:45,代码来源:unix.py

示例9: get_system_stats

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,代码行数:35,代码来源:config.py

示例10: test_collecting_disk_metrics

 def test_collecting_disk_metrics(self):
     """Testing disk stats gathering"""
     if Platform.is_unix():
         disk = Disk(logger)
         res = disk.check({})
         # Assert we have disk & inode stats
         assert len(res) == 2
         assert res[0]
         assert res[1]
开发者ID:Erni,项目名称:dd-agent,代码行数:9,代码来源:test_system.py

示例11: check_user_rights

 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]? ").lower()
         if choice 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:miketheman,项目名称:dd-agent,代码行数:9,代码来源:flare.py

示例12: _save_logs_path

 def _save_logs_path(self):
     prefix = ""
     if Platform.is_windows():
         prefix = "windows_"
     config = get_logging_config()
     self._collector_log = config.get("{0}collector_log_file".format(prefix))
     self._forwarder_log = config.get("{0}forwarder_log_file".format(prefix))
     self._dogstatsd_log = config.get("{0}dogstatsd_log_file".format(prefix))
     self._jmxfetch_log = config.get("jmxfetch_log_file")
开发者ID:miketheman,项目名称:dd-agent,代码行数:9,代码来源:flare.py

示例13: _save_logs_path

 def _save_logs_path(self):
     prefix = ''
     if Platform.is_windows():
         prefix = 'windows_'
     config = get_logging_config()
     self._collector_log = config.get('{0}collector_log_file'.format(prefix))
     self._forwarder_log = config.get('{0}forwarder_log_file'.format(prefix))
     self._dogstatsd_log = config.get('{0}dogstatsd_log_file'.format(prefix))
     self._jmxfetch_log = config.get('jmxfetch_log_file')
开发者ID:AquaBindi,项目名称:dd-agent,代码行数:9,代码来源:flare.py

示例14: _supervisor_status

 def _supervisor_status(self):
     if Platform.is_windows():
         print "Windows - status not implemented"
     else:
         agent_exec = self._get_path_agent_exec()
         print "{0} status".format(agent_exec)
         self._print_output_command([agent_exec, "status"])
         supervisor_exec = self._get_path_supervisor_exec()
         print "{0} status".format(supervisor_exec)
         self._print_output_command([supervisor_exec, "-c", self._get_path_supervisor_conf(), "status"])
开发者ID:miketheman,项目名称:dd-agent,代码行数:10,代码来源:flare.py

示例15: check

    def check(self, instance):
        if instance is None:
            instance = {}

        self._excluded_ifaces = instance.get('excluded_interfaces', [])
        self._collect_cx_state = instance.get('collect_connection_state', False)

        self._exclude_iface_re = None
        exclude_re = instance.get('excluded_interface_re', None)
        if exclude_re:
            self.log.debug("Excluding network devices matching: %s" % exclude_re)
            self._exclude_iface_re = re.compile(exclude_re)

        if Platform.is_linux():
            self._check_linux(instance)
        elif Platform.is_bsd():
            self._check_bsd(instance)
        elif Platform.is_solaris():
            self._check_solaris(instance)
开发者ID:Osterjour,项目名称:dd-agent,代码行数:19,代码来源:network.py


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