1: Install Psutil
#wgethttps://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz--no-check-certificate
#tar ZXVF psutil-2.0.0.tar.gz
#cd psutil-2.0.0
#python setup.py Install
2. Get System Performance Information
(1) CPU Information
>>>import Psutil
>>>psutil.cpu_times ()
Scputimes (user=135.42,nice=0.48, system=80.67, idle=693.5, iowait=124.58, irq=0.01, softirq=3.54,steal=0.0, guest= 0.0, guest_nice=0.0)
>>>psutil.cpu_times (). User # gets individual data information, such as the user 's CPU time
147.07
>>>psutil.cpu_count () # gets The logical number of CPUs, default llogical=true4
2
>>>psutil.cpu_count (logical=false) # gets The physical number of CPUs
2
(2) Memory information
>>>import Psutil
>>>mem = Psutil.virtual_memory () # use psutil.virtual_memory to get full memory information
>>>mem
Svmem (total=1029111808l,available=513196032l, percent=50.1, used=962969600l, free=66142208l,active=579526656, inactive=239161344, buffers=78082048l, cached=368971776)
>>>mem.total # Get total Memory
1029111808L
>>>mem.free # Get free memory number
66142208L
>>>psutil.swap_memory () # get swap partition information
Sswap (total=922742784l,used=5111808l, free=917630976l, percent=0.6, sin=45056, sout=5132288)
(3) disk information
>>>psutil.disk_partitions () # Get disk complete information using the Psutil.disk_partitions method
[Sdiskpart (device= '/dev/sda1 ', mountpoint= '/', fstype= ' ext4 ', opts= ' rw,relatime,errors=remount-ro,data=ordered '), Sdiskpart (device= '/dev/sr0 ', mountpoint= '/media/cdrom0 ', fstype= ' iso9660 ', opts= ' ro,nosuid,nodev,noexec,relatime ' )]
>>>psutil.disk_usage ('/') # use the Psutil.disk_usage method to get the usage of the partition
Sdiskusage (total=20091629568,used=10586230784, free=8461176832, percent=52.7)
>>>psutil.disk_io_counters () # gets the total IO of the hard disk , read and write information
Sdiskio (read_count=28282,write_count=2216, read_bytes=580173824, write_bytes=54259712, Read_time=447236,write_ time=777976)
>>>psutil.disk_io_counters (perdisk=true) # parameter perdisk=true get the number of individual partitions io , read and write information
{' fd0 ': Sdiskio (read_count=0, write_count=0, Read_bytes=0, Write_bytes=0, read_time=0,write_time=0), ' sr0 ': Sdiskio ( Read_count=33, Write_count=0, Read_bytes=92160,write_bytes=0, read_time=160, write_time=0), ' Sda5 ': Sdiskio (Read_ Count=118,write_count=20, read_bytes=1097728, write_bytes=5132288, read_time=248,write_time=880), ' sda2 ': Sdiskio ( read_count=2, Write_count=0, Read_bytes=2048,write_bytes=0, read_time=16, write_time=0), ' sda1 ': Sdiskio (read_count= 28129,write_count=2196, read_bytes=578981888, write_bytes=49127424, read_time=446812,write_time=777096)}
(4) Network information
>>>psutil.net_io_counters () # Get IO information for the network , default pernic=false
Snetio (bytes_sent=14974,bytes_recv=226027, packets_sent=132, packets_recv=202, errin=0, errout=0,dropin=0, dropout= 0)
>>>psutil.net_io_counters (pernic=true) # pernic=true output io information for each network interface
{' Lo ': Snetio (bytes_sent=1200, bytes_recv=1200, packets_sent=20, packets_recv=20,errin=0, errout=0, dropin=0, dropout =0), ' eth0 ': Snetio (bytes_sent=13774,bytes_recv=224827, packets_sent=112, packets_recv=182, errin=0, Errout=0,dropin =0, Dropout=0)}
(5) Other System Information
>>>psutil.users () # returns user information for the currently logged on system
[Suser (name= ' root ', terminal= ': 0 ', host= ': 0 ', started=1482396928.0)]
>>>import Psutil,datetime
>>>psutil.boot_time () # Get boot time, return in Linux time Format
1482396866.0
>>>datetime.datetime.fromtimestamp (Psutil.boot_time ()) # system boot time
Datetime.datetime (2016,12, 22, 16, 54, 26)
This article from "Do not forget Beginner's mind" blog, reproduced please contact the author!
python--System Information Module Psutil