psutil.cpu_times(percpu=False)

说明:
返回一个元组,包含cpu运行时间的各个参数。每一个参数的值代表cpu在给定模式下运行的秒数

  • user —运行在用户态的普通进程所消耗的cpu时间,在linux中这个时间包括guest时间
  • system —运行在内核态的进程所消耗的cpu时间
  • idle —cpu空闲时间

平台指定参数:

nice (UNIX) : time spent by niced (prioritized) processes executing in user mode; on Linux this also includes guest_nice time
iowait (Linux) : time spent waiting for I/O to complete
irq (Linux, BSD) : time spent for servicing hardware interrupts
softirq (Linux) : time spent for servicing software interrupts
steal (Linux 2.6.11+) : time spent by other operating systems running in a virtualized environment
guest (Linux 2.6.24+) : time spent running a virtual CPU for guest operating systems under the control of the Linux kernel
guest_nice (Linux 3.2.0+) : time spent running a niced guest (virtual CPU for guest operating systems under the control of the Linux kernel)
interrupt (Windows) : time spent for servicing hardware interrupts ( similar to “irq” on UNIX)
dpc (Windows) : time spent servicing deferred procedure calls (DPCs); DPCs are interrupts that run at a lower priority than standard interrupts.

当参数percpu=True时,返回一个列表,包含系统里所有逻辑CPU的运行参数。第一个参数代表第一个CPU,第二个参数代表第二个CPU,以此类推。

The order of the list is consistent across calls

In [1]: psutil.cpu_times()
Out[1]: scputimes(user=292.39, nice=0.08, system=99.33, idle=300619.63, iowait=64.31, irq=0.0, softirq=4.03, steal=0.0, guest=0.0, guest_nice=0.0)
In [2]: psutil.cpu_times(percpu=True)
Out[2]:
[scputimes(user=118.54, nice=0.07, system=46.51, idle=150864.2, iowait=27.19, irq=0.0, softirq=0.5, steal=0.0, guest=0.0, guest_nice=0.0),
 scputimes(user=174.09, nice=0.0, system=52.96, idle=150757.58, iowait=37.15, irq=0.0, softirq=3.53, steal=0.0, guest=0.0, guest_nice=0.0)]
psutil.cpu_percent(interval=None, percpu=False)

说明:
返回一个浮点数,表示在整个系统中cpu的利用率百分比。参数interval为0.0或者None时,将立即返回自上一次调用后的时间内的CPU运行时间结果。参数大于0.0时,则返回时间间隔内的CPU运行时间结果。因此,当interval是None或者0.0时,第一次调用的结果将返回0.0,你需要忽略这个返回值。如果需要精确的结果,推荐将interval设置为至少为0.1s。当percpu为True时,将返回一个列表,包含每个CPU的利用率。

In [31]: psutil.cpu_percent(interval=1, percpu=False)
Out[31]: 0.0
In [32]: psutil.cpu_percent(interval=1, percpu=True)
Out[32]: [0.0, 0.0]
psutil.cpu_times_percent(interval=None, percpu=False)

说明:
和cpu_times的返回值类似,只不过是换为了百分比形式。并且interval为None或者0.0时的返回情况和上一个方法的结果一样。不推荐使用第一次返回值。

psutil.cpu_count(logical=True)

说明:
返回逻辑CPU个数,如果不确定时,将返回None。如果logical=False,返回CPU物理核数。但是在OpenBSD和NetBSD系统中,psutil.cpu_count(logical=False)返回None。

len(psutil.Process().cpu_affinity())

返回当前可被进程使用的cpu数目

>>> psutil.cpu_count()
>>> psutil.cpu_count(logical=False)
>>> len(psutil.Process().cpu_affinity())
psutil.cpu_stats()

该方法在4.1.0中新增

psutil.cpu_freq(percpu=False)

该方法在5.1.0中新增,不过我装的是5.4.0,还是会报下面的错误
虚拟机下报错:

In [41]: psutil.cpu_freq(percpu=False)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-41-1a21b94419c9> in <module>()
----> 1 psutil.cpu_freq(percpu=False)
AttributeError: 'module' object has no attribute 'cpu_freq'
memory
psutil.virtual_memory()
psutil.swap_memory()
Disks
psutil.disk_partitions(all=False)

all=False时,尝试只返回物理设备(磁盘,cd-rom驱动,USB keys),不过并不是全平台可靠的。(e.g. on BSD this parameter is ignored)

psutil.disk_usage(path)

返回包含给定路径的磁盘的统计信息。

psutil.disk_io_counters(perdisk=False, nowrap=True)

返回系统级别的I/O统计信息

read_count: number of reads
write_count: number of writes
read_bytes: number of bytes read
write_bytes: number of bytes written

平台差异性返回值:
read_time: (all except NetBSD and OpenBSD) time spent reading from disk (in milliseconds)
write_time: (all except NetBSD and OpenBSD) time spent writing to disk (in milliseconds)
busy_time: (Linux, FreeBSD) time spent doing actual I/Os (in milliseconds)
read_merged_count (Linux): number of merged reads (see iostat doc)
write_merged_count (Linux): number of merged writes (see iostats doc)

If perdisk is True return the same information for every physical disk installed on the system as a dictionary with partition names as the keys and the named tuple described above as the values. See iotop.py for an example application. On some systems such as Linux, on a very busy or long-lived system, the numbers returned by the kernel may overflow and wrap (restart from zero). If nowrap is True psutil will detect and adjust those numbers across function calls and add “old value” to “new value” so that the returned numbers will always be increasing or remain the same, but never decrease. disk_io_counters.cache_clear() can be used to invalidate the nowrap cache.

Network OK, here’s another psutil release. Main highlights of this release are sensors-related APIs. 好,这是另一个psutil版本。 此版本的主要亮点是与传感器相关的API。 温度范围 ( Temperatures) It is now possible to retrieve hardware tempe... when i check the version of psutil in python it says i have version 0.5.0:$ uname -aLinux mypc 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux$ pythonPython 2.7.3 (default, Mar 13 2014, 1... 安装psutil模块,可以通过python获取系统的cpu,磁盘,内存,进程,网络等相关信息 下载地址https://pypi.python.org/pypi/psutil/ tar -zxvf psutil-2.1.3.tar.gz cd psutil-2.1.3  python setup.py install 安装是出现报错 error: command 'gcc' failed 参考官方文档:psutil是一个开源且跨平台(http://code.google.com/p/psutil/)的库,能够轻松实现获取系统运行的进程和系统利用率(包括CPU、内存、磁盘、网络等)信息。它主要应用于系统监控,分析和限制系统资源及进程的管理。它实现了同等命令行工具提供的功能,如ps、top、lsof、netstat、ifconfig、who、df、kill、free、nice、ionice、iostat、iotop、uptime、pidof、tty、taskset、pmap等。... Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法 2014年04月30日 ⁄ 测试工具, 软件测试 ⁄ 共 678字 ⁄ 字号 小 中 大 ⁄ 暂无评论 ⁄ 阅读 12,782 次 >>> psutil.cpu_times() scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, g... psutil (python system and process utilities) 是一个跨平台的第三方库,能够轻松实现获取系统运行的进程和系统利用率(包扩CPU、内存、磁盘、网络等)信息。它主要用于系统监控、分析、限制系统资源和进程的管理。它实现了同等命令行工具提供的功能,如ps、top、lsof、netstat、ifconfig、who、df、kill... Psutil(进程和系统实用程序)是一个跨平台的库,用于在Python中检索有关运行进程和系统资源利用率(CPU,内存,磁盘,网络)的信息。它主要用于系统监视,分析和限制系统资源及运行进程的管理。它实现了Linux命令工具提供的许多功能,例如:ps,top,lsof,netstat,ifconfig,who,df,kill,nice,ionice,iostat,iotop,uptime,pidos... psutil 1.简单介绍 psutil是一个跨平台的库(http://code.google.com/p/psutil/),能够轻松的实现获取系统运行的进程和系统利用率(CPU、内存、磁盘、网络等)信息。它主要应用于系统监控,分析和限制系统资源及进程的管理。能实现同等命令行工具提供的功能,如ps、top、lsof、netstat、ifconfig、who、df、kill、free、nice、io...