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


Python Platform.is_win32方法代码示例

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


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

示例1: collect_metrics_psutil

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
    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,代码行数:51,代码来源:disk.py

示例2: get_system_stats

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

示例3: collect_metrics_psutil

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
    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,代码行数:31,代码来源:disk.py

示例4: _exclude_disk_psutil

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
 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,代码行数:10,代码来源:disk.py

示例5: collect_metrics_psutil

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
    def collect_metrics_psutil(self):
        self._valid_disks = {}
        for part in psutil.disk_partitions(all=self._all_partitions):
            # we check all exclude conditions
            if self._exclude_disk_psutil(part):
                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).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:sebest,项目名称:dd-agent,代码行数:23,代码来源:disk.py

示例6: collect_metrics_psutil

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

            # 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)
        # And finally, latency metrics, a legacy gift from the old Windows Check
        if Platform.is_win32():
            self.collect_latency_metrics()
开发者ID:DataDog,项目名称:dd-agent,代码行数:40,代码来源:disk.py

示例7: get_system_stats

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

示例8: _load_conf

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
    def _load_conf(self, instance):
        self._excluded_filesystems = instance.get('excluded_filesystems', [])
        self._excluded_disks = instance.get('excluded_disks', [])
        self._tag_by_filesystem = _is_affirmative(
            instance.get('tag_by_filesystem', False))
        # On Windows, we need all_partitions to True by default to collect
        # metrics about remote disks
        # On Linux, we need all_partitions to False to avoid collecting metrics
        # about nodev filesystems
        self._all_partitions = _is_affirmative(
            instance.get('all_partitions', Platform.is_win32()))

        # FIXME: 6.x, drop use_mount option in datadog.conf
        self._load_legacy_option(instance, 'use_mount', False,
                                 operation=_is_affirmative)
        # FIXME: 6.x, drop device_blacklist_re option in datadog.conf
        self._load_legacy_option(instance, 'excluded_disk_re', '^$',
                                 legacy_name='device_blacklist_re',
                                 operation=re.compile)
开发者ID:kidanekal,项目名称:dd-agent,代码行数:21,代码来源:disk.py

示例9: collect_metrics_psutil

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

            # 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)
开发者ID:dadicool,项目名称:dd-agent,代码行数:40,代码来源:disk.py

示例10: _get_pickle_path

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
 def _get_pickle_path(cls):
     if Platform.is_win32():
         path = os.path.join(_windows_commondata_path(), 'Datadog', cls.__name__ + '.pickle')
     else:
         path = os.path.join(tempfile.gettempdir(), cls.__name__ + '.pickle')
     return path
开发者ID:jonathonwiebe,项目名称:dd-agent,代码行数:8,代码来源:check_status.py

示例11: BadConfException

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
# stdlib
import time

# 3p
import dns.resolver

# project
from util import Platform
from checks.network_checks import NetworkCheck, Status


# These imports are necessary because otherwise dynamic type
# resolution will fail on windows without it.
# See more here: https://github.com/rthalley/dnspython/issues/39.
if Platform.is_win32():
    from dns.rdtypes.ANY import *  # noqa
    from dns.rdtypes.IN import *  # noqa

class BadConfException(Exception):
    pass

class DNSCheck(NetworkCheck):
    SERVICE_CHECK_NAME = 'dns.can_resolve'
    DEFAULT_TIMEOUT = 5

    def __init__(self, name, init_config, agentConfig, instances):
        # Now that the DNS check is a Network check, we must provide a `name` for each
        # instance before calling NetworkCheck to make backwards compatible with old yaml.
        for idx, inst in enumerate(instances):
            try:
开发者ID:Everlane,项目名称:dd-agent,代码行数:32,代码来源:dns_check.py

示例12: get_process_metrics

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
    def get_process_metrics(self, pids, psutil, cpu_check_interval):

        # initialize process metrics
        # process metrics available for all versions of psutil
        rss = 0
        vms = 0
        cpu = 0
        thr = 0

        # process metrics available for psutil versions 0.6.0 and later
        extended_metrics_0_6_0 = self.is_psutil_version_later_than((0, 6, 0)) and \
            not Platform.is_win32()
        # On Windows get_ext_memory_info returns different metrics
        if extended_metrics_0_6_0:
            real = 0
            voluntary_ctx_switches = 0
            involuntary_ctx_switches = 0
        else:
            real = None
            voluntary_ctx_switches = None
            involuntary_ctx_switches = None

        # process metrics available for psutil versions 0.5.0 and later on UNIX
        extended_metrics_0_5_0_unix = self.is_psutil_version_later_than((0, 5, 0)) and \
                                Platform.is_unix()
        if extended_metrics_0_5_0_unix:
            open_file_descriptors = 0
        else:
            open_file_descriptors = None

        # process I/O counters (agent might not have permission to access)
        read_count = 0
        write_count = 0
        read_bytes = 0
        write_bytes = 0

        got_denied = False

        for pid in set(pids):
            try:
                p = psutil.Process(pid)
                if extended_metrics_0_6_0:
                    mem = p.get_ext_memory_info()
                    real += mem.rss - mem.shared
                    try:
                        ctx_switches = p.get_num_ctx_switches()
                        voluntary_ctx_switches += ctx_switches.voluntary
                        involuntary_ctx_switches += ctx_switches.involuntary
                    except NotImplementedError:
                        # Handle old Kernels which don't provide this info.
                        voluntary_ctx_switches = None
                        involuntary_ctx_switches = None
                else:
                    mem = p.get_memory_info()

                if extended_metrics_0_5_0_unix:
                    try:
                        open_file_descriptors += p.get_num_fds()
                    except psutil.AccessDenied:
                        got_denied = True

                rss += mem.rss
                vms += mem.vms
                thr += p.get_num_threads()
                cpu += p.get_cpu_percent(cpu_check_interval)

                # user agent might not have permission to call get_io_counters()
                # user agent might have access to io counters for some processes and not others
                if read_count is not None:
                    try:
                        io_counters = p.get_io_counters()
                        read_count += io_counters.read_count
                        write_count += io_counters.write_count
                        read_bytes += io_counters.read_bytes
                        write_bytes += io_counters.write_bytes
                    except psutil.AccessDenied:
                        self.log.info('DD user agent does not have access \
                            to I/O counters for process %d: %s' % (pid, p.name))
                        read_count = None
                        write_count = None
                        read_bytes = None
                        write_bytes = None

            # Skip processes dead in the meantime
            except psutil.NoSuchProcess:
                self.warning('Process %s disappeared while scanning' % pid)
                pass

        if got_denied:
            self.warning("The Datadog Agent was denied access when trying to get the number of file descriptors")

        #Memory values are in Byte
        return (thr, cpu, rss, vms, real, open_file_descriptors,
            read_count, write_count, read_bytes, write_bytes, voluntary_ctx_switches, involuntary_ctx_switches)
开发者ID:arthurnn,项目名称:dd-agent,代码行数:96,代码来源:process.py

示例13: get_process_metrics

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
    def get_process_metrics(self, pids, cpu_check_interval, ignore_denied_access=True):

        # initialize process metrics
        # process metrics available for all versions of psutil
        rss = 0
        vms = 0
        cpu = 0
        thr = 0
        voluntary_ctx_switches = 0
        involuntary_ctx_switches = 0

        # process metrics available for psutil versions 0.6.0 and later
        if Platform.is_win32() or Platform.is_solaris():
            real = None
        else:
            real = 0

        if Platform.is_unix():
            open_file_descriptors = 0
        else:
            open_file_descriptors = None

        # process I/O counters (agent might not have permission to access)
        read_count = 0
        write_count = 0
        read_bytes = 0
        write_bytes = 0

        got_denied = False

        for pid in set(pids):
            try:
                p = psutil.Process(pid)
                try:
                    if real is not None:
                        mem = p.memory_info_ex()
                        real += mem.rss - mem.shared
                    else:
                        mem = p.memory_info()

                    if Platform.is_unix():
                        ctx_switches = p.num_ctx_switches()
                        voluntary_ctx_switches += ctx_switches.voluntary
                        involuntary_ctx_switches += ctx_switches.involuntary

                    rss += mem.rss
                    vms += mem.vms
                    thr += p.num_threads()
                    cpu += p.cpu_percent(cpu_check_interval)

                    if open_file_descriptors is not None:
                        open_file_descriptors += p.num_fds()

                except NotImplementedError:
                    # Handle old Kernels which don't provide this info.
                    voluntary_ctx_switches = None
                    involuntary_ctx_switches = None
                except AttributeError:
                        self.log.debug("process attribute not supported on this platform")
                except psutil.AccessDenied:
                    got_denied = True

                # user agent might not have permission to call io_counters()
                # user agent might have access to io counters for some processes and not others
                if read_count is not None:
                    try:
                        io_counters = p.io_counters()
                        read_count += io_counters.read_count
                        write_count += io_counters.write_count
                        read_bytes += io_counters.read_bytes
                        write_bytes += io_counters.write_bytes
                    except AttributeError:
                        self.log.debug("process attribute not supported on this platform")
                    except psutil.AccessDenied:
                        log_func = self.log.debug if ignore_denied_access else self.log.info
                        log_func('dd-agent user does not have access \
                            to I/O counters for process %d: %s' % (pid, p.name()))
                        read_count = None
                        write_count = None
                        read_bytes = None
                        write_bytes = None

            # Skip processes dead in the meantime
            except psutil.NoSuchProcess:
                self.warning('Process %s disappeared while scanning' % pid)

        if got_denied and not ignore_denied_access:
            self.warning("The Datadog Agent was denied access when trying to get the number of file descriptors")

        #Memory values are in Byte
        return (thr, cpu, rss, vms, real, open_file_descriptors,
            read_count, write_count, read_bytes, write_bytes, voluntary_ctx_switches, involuntary_ctx_switches)
开发者ID:djensen47,项目名称:dd-agent,代码行数:94,代码来源:process.py

示例14: get_jmx_status_path

# 需要导入模块: from util import Platform [as 别名]
# 或者: from util.Platform import is_win32 [as 别名]
def get_jmx_status_path():
    if Platform.is_win32():
        path = os.path.join(_windows_commondata_path(), 'Datadog')
    else:
        path = tempfile.gettempdir()
    return path
开发者ID:frustra,项目名称:dd-agent,代码行数:8,代码来源:config.py


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