Reference: http://www.jbxue.com/python/29871.htm
1. Get System Performance Information
1) CPU Information
Returns the meaning of the item in the list of keywords in the content (own understanding, detailed explanation refer to this article):
- CPU time used by user
- CPU time used by System configuration
- Idle Free CPU time
- Nice (UNIX) user-configured CPU time for process allocations weighted by NICE (process priority correction)
- iowait (Linux) CPU waits for disk write completion time
- IRQ (Linux, FreeBSD) hard Interrupt consumption time
- SOFTIRQ (Linux) Soft interrupt consumption time
- Steal (Linux 2.6.11+) virtual machine steal time
- Guest (Linux 2.6.24+) CPU time used in guest status
- Guest_nice User-configured CPU time for a nice-weighted process (Linux 3.2.0+) Guest Status
>>> print U "CPU count%s"%psutil.cpu_count ()
Number of CPUs 1
>>> print U "Physical CPU Count%s"%psutil.cpu_count (Logical=false)
Number of physical CPUs 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) Memory Information
Total, amount of memory
Used, number of memory used
Free, number of idle memory
buffers, buffer usage number
Swap, swap partition usage number
>>> 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) disk Information
Disk Utilization and IO information
Read_count, read IO number
Write_count, write IO number
Read_bytes, number of Read Io bytes
Write_count, bytes of write IO
Read_time, Disk read time
Write_time, Disk 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) Network Information
bytes_sent, number of bytes sent
packets_sent, number of bytes received
Packets_sent, number of packets sent
Packets_sent, number of packets received
>>> 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) Other System Information
User Login, boot time
>>>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, System process Management method
1) Process Information
2) Use of the Popen class
Import Psutil from Import = Pstuil. Popen (['/etc/init.d/mysqld ', '-C ', ' Start '],stdout=pipe)
Applications launched through the Psutil Popen method can keep track of all the information that the program runs.
Python psutil Module Usage example