Psutil is a cross-platform library that makes it easy to get the process and system utilization (CPU, memory, disk, network, etc.) information of the system running, mainly used for system monitoring, analyzing and restricting the management of system resources and processes, which implements the functions provided by equivalent command line tools, such as Ps,top,lsof, Netstat,ifconfig,who,df,kill,free,nice and so on. Supports 32-bit, and 64-bit Linux,windows,os X,FREEBSD and other operating systems.
11CPU Information2 #there are several parts of the Linux system CPU utilization3 #User time, percentage of times to execute the process4 #System time, percent execution of kernel processes and interrupts5 #wait io, percent of time since IO waits for the CPU to be in idle (idle) state6 #idle,cpu Percentage of time in idle state7 8 ImportPsutil9 #Get CPU Completion informationTen Printpsutil.cpu_times () One>>> scputimes (user=29.36, nice=0.0, system=26.59, idle=9619.35, iowait=64.78, irq=0.5, softirq=1.67, steal= 0.0, guest=0.0) A - Printtype (Psutil.cpu_times ()) ->>> <class 'Psutil._pslinux.scputimes'> the #user () accumulates from the start of the system to the current time, the CPU time of the client state, and does not contain the nice value as a negative process. - #Nice () accumulates from the start of the system to the current moment, the CPU time occupied by a process with a negative nice value - #system () accumulates at the current time from the start of the boot, core time - #idle () accumulates from the start of the system to the current time, except for the wait time other than the IO wait time + #iowait () accumulated from the start of the system to the current time, IO wait time - #IRQ () accumulates from the start of the system to the current moment, hard interrupt time + #SOFTIRQ () accumulated from the start of the system to the current moment, soft interrupt time A at #CPU Usage Calculation -Total usage time of CPU in T1 to t2 period = (user2+ nice2+ system2+ idle2+ iowait2+ irq2+ softirq2)-(user1+ nice1+ system1+ idle1+ iowait1+ I rq1+softirq1) -CPU idle time in T1 to t2 period = (Idle2-idle1) -CPU in T1 to T2 time period instant utilization = 1-CPU idle use time/Total CPU Usage time - - # in PrintPsutil.cpu_percent (interval=20,percpu=False) ->>> 3.7 to interval: Represents the time, in seconds, during which the CPU utilization + PERCPU: Choose the total usage rate or the usage per CPU. False for overall, true for single, return list - the #get the number of CPU logic * PrintPsutil.cpu_count () $>>> 56Panax Notoginseng #calculation method: Number of *CPU per CPU (CPU cores This specification value, if HT is supported and turned on) - #Ht:intel's Hyper-Threading Technology (HT), can logically divide the number of CPU cores out the + A #Get CPU Physical number thePsutil.cpu_count (logical=False) +>>> 28 - #calculation method: Number of *CPU of single CPU cores
Python gets real-time information such as CPU, memory, hard disk Psutil