First you need to install the Psutil package
1 wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz-- No-check-certificate2 tar -zxvf psutil-2.0. 0. Tar . GZ 3 CD psutil-2.0. 0 4 Install
The installation is complete, and the Python version here is 3.4
Reference Psutil
1 Import Psutil
CPU utilization
The CPU utilization of the Linux operating system has the following parts:
User Time,执行用户进程的时间百分比;* System Time,执行内核进程和中断的时间百分比;* Wait IO,由于 IO 等待而使 CPU 处于 idle(空闲)状态的时间百分比;* Idle,CPU 处于 idle 状态的时间百分比
1 Import Psutil 2 psutil.cpu_times () # Use the Cpu_times method to get full CPU information, need to display all the logical CPU information, specify the method variable percpu=true, such as Psutil.cpu_time S (percpu=True)3psutil.cpu_times (). User # Gets individual data information, such as the user's CPU time compared to 4 psutil.cpu_ Count () # Gets the logical number of CPUs, default logical=True45 psutil.cpu_count (logical=false) # Gets the physical number of CPUs
-
Memory parameter
1 mem = Psutil.virtual_ Memory () # Use the Psutil.virtual_memory method to get the full information of the Ram 2 Mem.total # gets total memory 3 mem. free # Get free memory number 4 psutil.swap_memory () # Get swap partition information
Disk information
1 psutil.disk_partitions () # Get disk full information using the Psutil.disk_partitions method 2 psutil.disk_usage ( '/') # Use the Psutil.disk_usage method to get the partition (parameter) usage 3 Psutil.disk_io_ Counters () # Use Psutil.disk_io_counters to get the total IO number of the drive 4 psutil.disk_io_counters (perdisk=true) # " Perdisk=true "parameter gets the number of single partition IO
* Network Information
1 Psutil.net_io_counters () # Use Psutil.net_io_counters to get the total IO information of the network, default pernic=False2 psutil.net_ Io_counters (pernic=true) #pernic =true output IO information for each network interface
Python Psutil for System Management