python第三方模块之 ―― psutil系统性能信息模块

在此处获取最新版程序:

https://github.com/giampaolo/psutil

下载:

wget https://pypi.python.org/packages/source/p/psutil/psutil-2.1.3.tar.gz

安装python-devel


yum -y install python-devel


安装psutil:

tar -zxf psutil-2.1.3.tar.gz
cd psutil-2.1.3
python setup.py --help# 查看安装选项
python setup.py install# 直接安装


----- cpu:

>>> import psutil
>>> psutil.cpu_# cpu的几种方法
psutil.cpu_count(          psutil.cpu_times(          
psutil.cpu_percent(        psutil.cpu_times_percent( 
>>> psutil.cpu_count()#返回系统cpu核数,2科4核cpu,则返回8核
1
>>> psutil.cpu_percent()# 返回cpu负载百分比
0.20000000000000001
>>> psutil.cpu_times()
scputimes(user=5.79, nice=0.0, system=9.6999999999999993, idle=2857.8800000000001, iowait=60.939999999999998, irq=0.029999999999999999, softirq=1.8200000000000001, steal=0.0, guest=0.0)
>>> psutil.cpu_times_percent()
scputimes(user=0.0, nice=0.0, system=0.10000000000000001, idle=99.799999999999997, iowait=0.0, irq=0.0, softirq=0.10000000000000001, steal=0.0, guest=0.0)
>>>


----- mem:

>>> psutil.virtual_memory()
svmem(total=1028456448L, available=883007488L, percent=14.1, used=400318464L, free=628137984L, active=185749504, inactive=139575296, buffers=22106112L, cached=232763392)
>>> psutil.swap_memory()
sswap(total=1073737728L, used=0L, free=1073737728L, percent=0.0, sin=0, sout=0)

----- disk:

>>> psutil.disk_
psutil.disk_io_counters(  psutil.disk_partitions(   psutil.disk_usage(
####
>>> psutil.disk_partitions(all=False)
[sdiskpart(device='/dev/sda2', mountpoint='/', fstype='ext4', opts='rw'), sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='ext4', opts='rw')]
>>> psutil.disk_partitions(all=True) 
[sdiskpart(device='/dev/sda2', mountpoint='/', fstype='ext4', opts='rw'), sdiskpart(device='proc', mountpoint='/proc', fstype='proc', opts='rw'), sdiskpart(device='sysfs', mountpoint='/sys', fstype='sysfs', opts='rw'), sdiskpart(device='devpts', mountpoint='/dev/pts', fstype='devpts', opts='rw,gid=5,mode=620'), sdiskpart(device='tmpfs', mountpoint='/dev/shm', fstype='tmpfs', opts='rw'), sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='ext4', opts='rw'), sdiskpart(device='', mountpoint='/proc/sys/fs/binfmt_misc', fstype='binfmt_misc', opts='rw')]
>>> 
>>> psutil.disk_partitions()        # 默认all=False
[sdiskpart(device='/dev/sda2', mountpoint='/', fstype='ext4', opts='rw'), sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='ext4', opts='rw')]
### 
>>> psutil.disk_io_counters(perdisk=False)
sdiskio(read_count=7139, write_count=1752, read_bytes=249808896, write_bytes=24270848, read_time=89756, write_time=45411)
>>> psutil.disk_io_counters(perdisk=True) 
{'sda2': sdiskio(read_count=6223, write_count=1745, read_bytes=245949440, write_bytes=24256512, read_time=83233, write_time=45385), 'sda3': sdiskio(read_count=332, write_count=0, read_bytes=1486848, write_bytes=0, read_time=1913, write_time=0), 'sda1': sdiskio(read_count=584, write_count=7, read_bytes=2372608, write_bytes=14336, read_time=4610, write_time=26)}
### 
>>> psutil.disk_usage('/dev/sda1')
sdiskusage(total=502624256, used=229376, free=502394880, percent=0.0)
>>>


更多实例参考:

https://github.com/giampaolo/psutil


你可能感兴趣的:(psutil,python第三方模块)