[Python Study Notes] Psutil module

Source: Internet
Author: User

System Performance Information Module Psutil

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.

Get System Performance Information

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>>>psutil.cpu_times () OneScputimes (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   - #gets the user's CPU time ratio ->>>psutil.cpu_times (). User the34.54 -   - #get the number of CPU logic ->>>Psutil.cpu_count () +4 -   + #Get CPU Physical number A>>> Psutil.cpu_count (logical=False) at4 -   -2Memory Information - #Memory utilization information for Linux systems involves - #Total Memory Totals - #used amount of memory used in #Free Memory Number - #Buffers Buffer Usage number to #Cache Usage Number + #Swap Swap partition usage number, etc. - #use Psutil.virtual_memory () with the Psutil.memory () method to get the   * #Get full Memory information $>>>mem =psutil.virtual_memory ()Panax Notoginseng>>>Mem -Svmem (total=1961488384, available=1483986944, percent=24.3, used=341475328, free=941473792, active=677801984, inactive=212774912, buffers=32038912, cached=646500352, shared=4116480) the   + #Get Total Memory A>>>Mem.total the1961488384 +   - #gets the number of free memory $>>>Mem.free $941473792 -   - #get swap partition information the>>>psutil.swap_memory () -Sswap (total=2147475456, Used=0, free=2147475456, percent=0.0, sin=0, sout=0)Wuyi   the3Disk Information - #disk utilization using the Psutil.disk_usage () method gets Wu #IO information - #read_count Read IO number About #Write_count Write io number $ #read_bytes IO read byte number - #write_bytes IO write byte number - #read_time Disk Read Time - #write_time Disk Write Time A #use Psutil.disk_io_counters () to get +   the #Get disk complete information ->>>psutil.disk_partitions () $[Sdiskpart (device='/dev/sda3', mountpoint='/', fstype='Ext4', opts='RW'), Sdiskpart (device='/dev/sda1', mountpoint='/ Boot', fstype='Ext4', opts='RW')] the   the #get/Partition usage the>>> Psutil.disk_usage ('/') theSdiskusage (total=18506760192, used=4438568960, free=13128093696, percent=25.3) -   in #get total io of HDD the>>>psutil.disk_io_counters () the   About4Network Information the #bytes_sent number of bytes sent the #bytes_recv Number of bytes received the #packets_sent number of packets sent + #PACKEST_RECV received packet number - #use Psutil.net_io_counters () to get the>>>psutil.net_io_counters ()Bayi   the   the5Other System Information - #the Psutil module also supports obtaining user login, boot time and other information - #displays user information for the currently logged on system the>>>psutil.users () the   the #Get boot time the>>> Psutil.boot_time ()

System Process Management Methods

1 #list PID for all processes2>>>Psutil.pids ()3  4 #instantiate a Process object with the parameter as a PID5>>>p = Psutil. Process (3197)6  7 #Process Name8>>>p.name ()9 'Python3'Ten   One #Process Bin Path A>>>P.exe () - '/opt/python3/bin/python3.5' -   the #process Work Absolute path ->>>P.CWD () -   - #process Status +>>>p.status () -   + #Process creation Time A>>>p.create_time () at   - #UID Information ->>>P.uids () -   - #GID Information ->>>P.gids () in   - #process CPU time, including User,system two time to>>>p.cpu_times () +   - #Process Memory Utilization the>>>p.memory_percent () *   $ #Process Memory Rss,vms informationPanax Notoginseng>>>P.memory_info () -   the #Process IO Information +>>>p.io_counters () A   the #number of threads opened by the process +>>> P.num_threads ()

[Python Study Notes] Psutil module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.