标签:
参考:http://www.jbxue.com/python/29871.htm
1,获取系统性能信息
1)cpu信息
返回内容中关键字的列表中项的意义(自己的理解,详细解释参考此文章):
>>> print u"CPU 个数 %s"%psutil.cpu_count()
CPU 个数 1
>>> print u"物理CPU个数 %s"%psutil.cpu_count(logical=False)
物理CPU个数 1
>>> psutil.cpu_count(logical=True) 1 >>> psutil.cpu_times() scputimes(user=541.82, nice=1.32, system=781.5, idle=11678.47, iowait=42.81, irq=3.14, softirq=3.56, steal=0.0, guest=0.0) >>> psutil.cpu_percent() 1.1 >>> psutil.cpu_times_percent() scputimes(user=0.5, nice=0.0, system=0.5, idle=98.6, iowait=0.2, irq=0.0, softirq=0.0, steal=0.0, guest=0.0)
2)内存信息
total, 内存总量
used, 已使用的内存数
free, 空闲内存数
buffers, 缓冲区使用数
swap, 交换分区使用数
>>> psutil.swap_memory() sswap(total=3221221376L, used=0L, free=3221221376L, percent=0.0, sin=0, sout=0) >>> psutil.virtual_memory() svmem(total=1036587008L, available=697393152L, percent=32.7, used=877322240L, free=159264768L, active=243052544, inactive=459927552, buffers=44429312L, cached=493699072)
3)磁盘信息
磁盘利用率及IO信息
read_count,读IO数
write_count,写IO数
read_bytes,读IO字节数
write_count,写IO字节数
read_time,磁盘读时间
write_time,磁盘写时间
>>> psutil.disk_partitions() [sdiskpart(device=‘/dev/sda3‘, mountpoint=‘/‘, fstype=‘ext4‘, opts=‘rw‘), sdiskpart(device=‘/dev/sda1‘, mountpoint=‘/boot‘, fstype=‘ext4‘, opts=‘rw‘)] >>> psutil.disk_usage(‘/‘) sdiskusage(total=28090511360, used=3418284032, free=23238459392, percent=12.2) >>> psutil.disk_usage(‘/boot‘) sdiskusage(total=296236032, used=33723392, free=246784000, percent=11.4) >>> psutil.disk_io_counters(‘perdisk=False/True‘) {‘sda2‘: sdiskio(read_count=328, write_count=0, read_bytes=1470464, write_bytes=0, read_time=281, write_time=0), ‘sda3‘: sdiskio(read_count=12427, write_count=8975, read_bytes=392832000, write_bytes=192872448, read_time=95939, write_time=102753), ‘sda1‘: sdiskio(read_count=500, write_count=3, read_bytes=2026496, write_bytes=9216, read_time=237, write_time=2)}
4)网络信息
bytes_sent,发送字节数
packets_sent,接收字节数
packets_sent,发送数据包数
packets_sent,接收数据包数
>>> psutil.net_io_counters(pernic=False/True)
snetio(bytes_sent=64530, bytes_recv=817240, packets_sent=887, packets_recv=2600, errin=0, errout=0, dropin=0, dropout=0)
5)其他系统信息
用户登录、开机时间
>>> psutil.users() [suser(name=‘wst‘, terminal=‘tty1‘, host=‘localhost‘, started=1436421376.0), suser(name=‘wst‘, terminal=‘pts/0‘, host=‘localhost‘, started=1436427392.0), suser(name=‘wst‘, terminal=‘pts/1‘, host=‘localhost‘, started=1436429696.0)] >>> psutil.boot_time() 1436421348.0
2,系统进程管理方法
1)进程信息
2)popen类的使用
import psutil from subprocess import PIPE p = pstuil.Popen([‘/etc/init.d/mysqld’,’-c’,’start’],stdout=PIPE)
通过psutil的Popen方法启动的应用程序,可以跟踪该程序运行的所有信息。
标签:
原文地址:http://www.cnblogs.com/python-life/p/4662379.html