需要深入了解python psutil outpu

2024-04-29 03:07:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个脚本来被动地监视计算机上的资源使用情况。我想监控磁盘和网络IO,CPU和RAM的使用情况。它工作得很好。我现在正试图将这些信息解析为一个更具可读性的输出。我使用psutil for python2.7收集资源信息。我现在正在尝试分析每秒的磁盘使用情况。我想我只需要计算一下每秒钟的读写差异来计算每秒的使用量。不过,我不确定psutil对IO计数器使用的是什么计量单位。下面是psutil的输出示例。在

{'PhysicalDrive1': iostat", "read_count=379172, write_count=1688031, read_bytes=11142501376L, write_bytes=84719621632L, read_time=1280719510L, write_time=3614153510L), 'PhysicalDrive0': iostat", "read_count=481, write_count=0, read_bytes=1713152L, write_bytes=0L, read_time=6110L, write_time=0L), 'PhysicalDrive3': iostat", "read_count=105, write_count=42, read_bytes=377344L, write_bytes=24576L, read_time=137740L, write_time=35020L), 'PhysicalDrive2': iostat", 'read_count=646025, write_count=924922, read_bytes=14357518848L, write_bytes=17206760448L, read_time=146876820L, write_time=80879980L)}

我看到它提到iostat,我相信它也是linux中一个监视磁盘使用情况的程序。不管是谁,我一下子就看到读写数。很好,但是计量单位是什么?磁盘扇区?KB?不知道怎么数。在这之后,我读了字节和写了字节,我假设度量是字节,但是每个数字后面都有一个大写字母L。这是什么意思?只是想弄清楚psutil数字到底显示了什么:)谢谢!在


Tags: io信息read字节bytestimecount情况
1条回答
网友
1楼 · 发布于 2024-04-29 03:07:12

根据psutils doc

Return system disk I/O statistics as a namedtuple including the following attributes:

  • read_count: number of reads
  • write_count: number of writes
  • read_bytes: number of bytes read
  • write_bytes: number of bytes written
  • read_time: time spent reading from disk (in milliseconds)
  • write_time: time spent writing to disk (in milliseconds)

在python中,L前面跟一个整数意味着这个数字是一个Python Long类型,它是一个无限精度的整数(与标准python Int类型相反,它至少是一个在C long类型上实现的32位精度整数(实际精度可以从sys.maxint.bit_length()中获得)。在

相关问题 更多 >