當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。