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


Python psutil.disk_io_counters方法代码示例

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


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

示例1: getSystemInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def getSystemInfo(cls):
        system = {
            'boot_time': psutil.boot_time(),
            'cpu_count': psutil.cpu_count(),
            'cpu_stats': psutil.cpu_stats().__dict__,
            'cpu_times': [k.__dict__ for k in psutil.cpu_times(percpu=True)],
            'disk_io_counters': psutil.disk_io_counters().__dict__,
            'disk_usage': [],
            'net_io_counters': psutil.net_io_counters().__dict__,
            'swap_memory': psutil.swap_memory().__dict__,
            'virtual_memory': psutil.virtual_memory().__dict__
        }

        partitions = psutil.disk_partitions()
        for p in partitions:
            if p.mountpoint in cls.INCLUDED_PARTITIONS:
                usage = psutil.disk_usage(p.mountpoint)
                system['disk_usage'].append({
                    'mountpoint': p.mountpoint,
                    'total': usage.total,
                    'used': usage.used
                })

        return system 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:26,代码来源:system_status.py

示例2: _crawl_disk_io_counters

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def _crawl_disk_io_counters(self):
        try:
            disk_counters = psutil.disk_io_counters(perdisk=True)
            for device_name in disk_counters:
                counters = disk_counters[device_name]
                curr_counters = [
                    counters.read_count,
                    counters.write_count,
                    counters.read_bytes,
                    counters.write_bytes
                ]
                logger.debug(
                    u'Disk I/O counters - {0}: {1}'.format(device_name,
                                                           curr_counters))
                yield (device_name, curr_counters)
        except OSError as e:
            logger.debug(
                u'Caught exception when crawling disk I/O counters: {0}'.
                format(e)) 
开发者ID:cloudviz,项目名称:agentless-system-crawler,代码行数:21,代码来源:diskio_host_crawler.py

示例3: test_serialization

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_serialization(self):
        def check(ret):
            if json is not None:
                json.loads(json.dumps(ret))
            a = pickle.dumps(ret)
            b = pickle.loads(a)
            self.assertEqual(ret, b)

        check(psutil.Process().as_dict())
        check(psutil.virtual_memory())
        check(psutil.swap_memory())
        check(psutil.cpu_times())
        check(psutil.cpu_times_percent(interval=0))
        check(psutil.net_io_counters())
        if LINUX and not os.path.exists('/proc/diskstats'):
            pass
        else:
            if not APPVEYOR:
                check(psutil.disk_io_counters())
        check(psutil.disk_partitions())
        check(psutil.disk_usage(os.getcwd()))
        check(psutil.users()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_misc.py

示例4: test_cache_clear_public_apis

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_cache_clear_public_apis(self):
        psutil.disk_io_counters()
        psutil.net_io_counters()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.disk_io_counters', cache)
            self.assertIn('psutil.net_io_counters', cache)

        psutil.disk_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.net_io_counters', cache)
            self.assertNotIn('psutil.disk_io_counters', cache)

        psutil.net_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        self.assertEqual(caches, ({}, {}, {}))


# ===================================================================
# --- Example script tests
# =================================================================== 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_misc.py

示例5: test_disk_io_counters_kernel_2_4_mocked

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_disk_io_counters_kernel_2_4_mocked(self):
        # Tests /proc/diskstats parsing format for 2.4 kernels, see:
        # https://github.com/giampaolo/psutil/issues/767
        with mock_open_content(
                '/proc/partitions',
                textwrap.dedent("""\
                    major minor  #blocks  name

                       8        0  488386584 hda
                    """)):
            with mock_open_content(
                    '/proc/diskstats',
                    "   3     0   1 hda 2 3 4 5 6 7 8 9 10 11 12"):
                ret = psutil.disk_io_counters(nowrap=False)
                self.assertEqual(ret.read_count, 1)
                self.assertEqual(ret.read_merged_count, 2)
                self.assertEqual(ret.read_bytes, 3 * SECTOR_SIZE)
                self.assertEqual(ret.read_time, 4)
                self.assertEqual(ret.write_count, 5)
                self.assertEqual(ret.write_merged_count, 6)
                self.assertEqual(ret.write_bytes, 7 * SECTOR_SIZE)
                self.assertEqual(ret.write_time, 8)
                self.assertEqual(ret.busy_time, 10) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:test_linux.py

示例6: test_disk_io_counters_kernel_2_6_full_mocked

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_disk_io_counters_kernel_2_6_full_mocked(self):
        # Tests /proc/diskstats parsing format for 2.6 kernels,
        # lines reporting all metrics:
        # https://github.com/giampaolo/psutil/issues/767
        with mock_open_content(
                '/proc/partitions',
                textwrap.dedent("""\
                    major minor  #blocks  name

                       8        0  488386584 hda
                    """)):
            with mock_open_content(
                    '/proc/diskstats',
                    "   3    0   hda 1 2 3 4 5 6 7 8 9 10 11"):
                ret = psutil.disk_io_counters(nowrap=False)
                self.assertEqual(ret.read_count, 1)
                self.assertEqual(ret.read_merged_count, 2)
                self.assertEqual(ret.read_bytes, 3 * SECTOR_SIZE)
                self.assertEqual(ret.read_time, 4)
                self.assertEqual(ret.write_count, 5)
                self.assertEqual(ret.write_merged_count, 6)
                self.assertEqual(ret.write_bytes, 7 * SECTOR_SIZE)
                self.assertEqual(ret.write_time, 8)
                self.assertEqual(ret.busy_time, 10) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:test_linux.py

示例7: test_procfs_path

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_procfs_path(self):
        tdir = tempfile.mkdtemp()
        try:
            psutil.PROCFS_PATH = tdir
            self.assertRaises(IOError, psutil.virtual_memory)
            self.assertRaises(IOError, psutil.cpu_times)
            self.assertRaises(IOError, psutil.cpu_times, percpu=True)
            self.assertRaises(IOError, psutil.boot_time)
            # self.assertRaises(IOError, psutil.pids)
            self.assertRaises(IOError, psutil.net_connections)
            self.assertRaises(IOError, psutil.net_io_counters)
            self.assertRaises(IOError, psutil.net_if_stats)
            self.assertRaises(IOError, psutil.disk_io_counters)
            self.assertRaises(IOError, psutil.disk_partitions)
            self.assertRaises(psutil.NoSuchProcess, psutil.Process)
        finally:
            psutil.PROCFS_PATH = "/proc"
            os.rmdir(tdir) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_linux.py

示例8: test_sector_size_mock

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_sector_size_mock(self):
        # Test SECTOR_SIZE fallback in case 'hw_sector_size' file
        # does not exist.
        def open_mock(name, *args, **kwargs):
            if PY3 and isinstance(name, bytes):
                name = name.decode()
            if "hw_sector_size" in name:
                flag.append(None)
                raise IOError(errno.ENOENT, '')
            else:
                return orig_open(name, *args, **kwargs)

        flag = []
        orig_open = open
        patch_point = 'builtins.open' if PY3 else '__builtin__.open'
        with mock.patch(patch_point, side_effect=open_mock):
            psutil.disk_io_counters()
            assert flag 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_linux.py

示例9: test_cache_clear_public_apis

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_cache_clear_public_apis(self):
        if not psutil.disk_io_counters() or not psutil.net_io_counters():
            return self.skipTest("no disks or NICs available")
        psutil.disk_io_counters()
        psutil.net_io_counters()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.disk_io_counters', cache)
            self.assertIn('psutil.net_io_counters', cache)

        psutil.disk_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.net_io_counters', cache)
            self.assertNotIn('psutil.disk_io_counters', cache)

        psutil.net_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        self.assertEqual(caches, ({}, {}, {}))


# ===================================================================
# --- Example script tests
# =================================================================== 
开发者ID:giampaolo,项目名称:psutil,代码行数:26,代码来源:test_misc.py

示例10: test_emulate_kernel_2_4

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_emulate_kernel_2_4(self):
        # Tests /proc/diskstats parsing format for 2.4 kernels, see:
        # https://github.com/giampaolo/psutil/issues/767
        with mock_open_content(
                '/proc/diskstats',
                "   3     0   1 hda 2 3 4 5 6 7 8 9 10 11 12"):
            with mock.patch('psutil._pslinux.is_storage_device',
                            return_value=True):
                ret = psutil.disk_io_counters(nowrap=False)
                self.assertEqual(ret.read_count, 1)
                self.assertEqual(ret.read_merged_count, 2)
                self.assertEqual(ret.read_bytes, 3 * SECTOR_SIZE)
                self.assertEqual(ret.read_time, 4)
                self.assertEqual(ret.write_count, 5)
                self.assertEqual(ret.write_merged_count, 6)
                self.assertEqual(ret.write_bytes, 7 * SECTOR_SIZE)
                self.assertEqual(ret.write_time, 8)
                self.assertEqual(ret.busy_time, 10) 
开发者ID:giampaolo,项目名称:psutil,代码行数:20,代码来源:test_linux.py

示例11: test_emulate_kernel_2_6_full

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_emulate_kernel_2_6_full(self):
        # Tests /proc/diskstats parsing format for 2.6 kernels,
        # lines reporting all metrics:
        # https://github.com/giampaolo/psutil/issues/767
        with mock_open_content(
                '/proc/diskstats',
                "   3    0   hda 1 2 3 4 5 6 7 8 9 10 11"):
            with mock.patch('psutil._pslinux.is_storage_device',
                            return_value=True):
                ret = psutil.disk_io_counters(nowrap=False)
                self.assertEqual(ret.read_count, 1)
                self.assertEqual(ret.read_merged_count, 2)
                self.assertEqual(ret.read_bytes, 3 * SECTOR_SIZE)
                self.assertEqual(ret.read_time, 4)
                self.assertEqual(ret.write_count, 5)
                self.assertEqual(ret.write_merged_count, 6)
                self.assertEqual(ret.write_bytes, 7 * SECTOR_SIZE)
                self.assertEqual(ret.write_time, 8)
                self.assertEqual(ret.busy_time, 10) 
开发者ID:giampaolo,项目名称:psutil,代码行数:21,代码来源:test_linux.py

示例12: test_emulate_kernel_2_6_limited

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_emulate_kernel_2_6_limited(self):
        # Tests /proc/diskstats parsing format for 2.6 kernels,
        # where one line of /proc/partitions return a limited
        # amount of metrics when it bumps into a partition
        # (instead of a disk). See:
        # https://github.com/giampaolo/psutil/issues/767
        with mock_open_content(
                '/proc/diskstats',
                "   3    1   hda 1 2 3 4"):
            with mock.patch('psutil._pslinux.is_storage_device',
                            return_value=True):
                ret = psutil.disk_io_counters(nowrap=False)
                self.assertEqual(ret.read_count, 1)
                self.assertEqual(ret.read_bytes, 2 * SECTOR_SIZE)
                self.assertEqual(ret.write_count, 3)
                self.assertEqual(ret.write_bytes, 4 * SECTOR_SIZE)

                self.assertEqual(ret.read_merged_count, 0)
                self.assertEqual(ret.read_time, 0)
                self.assertEqual(ret.write_merged_count, 0)
                self.assertEqual(ret.write_time, 0)
                self.assertEqual(ret.busy_time, 0) 
开发者ID:giampaolo,项目名称:psutil,代码行数:24,代码来源:test_linux.py

示例13: test_emulate_include_partitions

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_emulate_include_partitions(self):
        # Make sure that when perdisk=True disk partitions are returned,
        # see:
        # https://github.com/giampaolo/psutil/pull/1313#issuecomment-408626842
        with mock_open_content(
                '/proc/diskstats',
                textwrap.dedent("""\
                    3    0   nvme0n1 1 2 3 4 5 6 7 8 9 10 11
                    3    0   nvme0n1p1 1 2 3 4 5 6 7 8 9 10 11
                    """)):
            with mock.patch('psutil._pslinux.is_storage_device',
                            return_value=False):
                ret = psutil.disk_io_counters(perdisk=True, nowrap=False)
                self.assertEqual(len(ret), 2)
                self.assertEqual(ret['nvme0n1'].read_count, 1)
                self.assertEqual(ret['nvme0n1p1'].read_count, 1)
                self.assertEqual(ret['nvme0n1'].write_count, 5)
                self.assertEqual(ret['nvme0n1p1'].write_count, 5) 
开发者ID:giampaolo,项目名称:psutil,代码行数:20,代码来源:test_linux.py

示例14: test_procfs_path

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def test_procfs_path(self):
        tdir = self.get_testfn()
        os.mkdir(tdir)
        try:
            psutil.PROCFS_PATH = tdir
            self.assertRaises(IOError, psutil.virtual_memory)
            self.assertRaises(IOError, psutil.cpu_times)
            self.assertRaises(IOError, psutil.cpu_times, percpu=True)
            self.assertRaises(IOError, psutil.boot_time)
            # self.assertRaises(IOError, psutil.pids)
            self.assertRaises(IOError, psutil.net_connections)
            self.assertRaises(IOError, psutil.net_io_counters)
            self.assertRaises(IOError, psutil.net_if_stats)
            # self.assertRaises(IOError, psutil.disk_io_counters)
            self.assertRaises(IOError, psutil.disk_partitions)
            self.assertRaises(psutil.NoSuchProcess, psutil.Process)
        finally:
            psutil.PROCFS_PATH = "/proc" 
开发者ID:giampaolo,项目名称:psutil,代码行数:20,代码来源:test_linux.py

示例15: collect_disk

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import disk_io_counters [as 别名]
def collect_disk(self, stat):
		d = psutil.disk_io_counters(perdisk=False)
		stat['psutil_disk'] = {	'read_count':d.read_count,
					'write_count':d.write_count,
					'read_bytes':d.read_bytes,
					'write_bytes':d.write_bytes,
					'read_time':d.read_time,
					'write_time':d.write_time }
			
		ds = psutil.disk_io_counters(perdisk=True)
		for k, d in ds.items():
			stat['psutil_disk-%s' % k] = {	'read_count':d.read_count,
						'write_count':d.write_count,
						'read_bytes':d.read_bytes,
						'write_bytes':d.write_bytes,
						'read_time':d.read_time,
						'write_time':d.write_time } 
开发者ID:naver,项目名称:hubblemon,代码行数:19,代码来源:client_psutil_plugin.py


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