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

Python util.Platform类代码示例

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

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



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


示例16: _collect_part_metrics

    def _collect_part_metrics(self, part, usage):
        metrics = {}
        for name in ['total', 'used', 'free']:
            # For legacy reasons,  the standard unit it kB
            metrics[self.METRIC_DISK.format(name)] = getattr(usage, name) / 1024.0
        # FIXME: 6.x, use percent, a lot more logical than in_use
        metrics[self.METRIC_DISK.format('in_use')] = usage.percent / 100.0
        if Platform.is_unix():
            metrics.update(self._collect_inodes_metrics(part.mountpoint))

        return metrics
开发者ID:AltSchool,项目名称:dd-agent,代码行数:11,代码来源:disk.py


示例17: testMemory

 def testMemory(self):
     global logger
     res = Memory(logger).check({})
     if Platform.is_linux():
         for k in ("swapTotal", "swapFree", "swapPctFree", "swapUsed", "physTotal", "physFree", "physUsed", "physBuffers", "physCached", "physUsable", "physPctUsable", "physShared"):
             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:Erni,项目名称:dd-agent,代码行数:11,代码来源:test_system.py


示例18: _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:AquaBindi,项目名称:dd-agent,代码行数:12,代码来源:flare.py


示例19: check

 def check(self, instance):
     """Get disk space/inode stats"""
     # Windows and Mac will always have psutil
     # (we have packaged for both of them)
     if self._psutil():
         if Platform.is_linux():
             procfs_path = self.agentConfig.get('procfs_path', '/proc').rstrip('/')
             psutil.PROCFS_PATH = procfs_path
         self.collect_metrics_psutil()
     else:
         # FIXME: implement all_partitions (df -a)
         self.collect_metrics_manually()
开发者ID:AltSchool,项目名称:dd-agent,代码行数:12,代码来源:disk.py


示例20: check

    def check(self, instance):
        host, port, user, password, mysql_sock, defaults_file, tags, options = self._get_config(instance)

        if (not host or not user) and not defaults_file:
            raise Exception("Mysql host and user are needed.")

        db = self._connect(host, port, mysql_sock, user, password, defaults_file)

        # Metric collection
        self._collect_metrics(host, db, tags, options)
        if Platform.is_linux():
            self._collect_system_metrics(host, db, tags)
开发者ID:anthonyjohnson,项目名称:dd-agent,代码行数:12,代码来源:mysql.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.PriorityQueue类代码示例发布时间:2022-05-26
下一篇:
Python util.PidFile类代码示例发布时间: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