Module: Psutil
Psutil is a cross-platform library that makes it easy for us to get information about the process and resource utilization of the system running.
Function: mainly for the system monitoring
Installation:
wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz--NO-CHECK-CERTIFICATETAR-ZXVF PSUTIL-2.0.0.TAR.GZCD Psutil-2.0.0python setup.py Install
CPU Information:
CPU utilization mainly includes the following parts
- User time, percentage of times to execute the process
- System time, percent execution of kernel processes and interrupts
- Wait io, percentage of time that the CPU is idle (idle) due to IO waiting
- Idle,cpu percentage of time in idle state
Psutil.cpu_times () How to use:
#import Psutil#psutil.cpu_times (percpu=true) # Use the Cpu_times method to obtain CPU complete information, need to display all logical CPU information, PERCPU = True Optional #psutil.cpu_ Times (). User # Gets the individual data information, such as the user's CPU time compared to #psutil.cpu_count () # Gets the logical number of CPUs, the default Logical=true#psytil.cpu_count (logical= False) # Gets the physical number of CPUs
Memory Information:
Memory information mainly includes the following parts:
- Total (amount of memory)
- Used (number of memory used)
- Free (number of idle memory)
- Buffers (number of buffers used)
- Cache (number of cached uses)
- Swap (Swap partition usage)
Psutil.virtual_memory () and Psutil.swap_memory () method of use:
#import psutil#mem=psutil.virtual_memory () # Get memory Full information #print (MEM) #mem. Total # Get memory totals #mem.free # Get free memory number #psutil.swap_ Memory () # Get swap partition information
Disk Information:
Disk information mainly includes the following sections:
- Read_count (read IO number)
- Write_time (write IO number)
- Read_bytes (io Read bytes)
- Read_time (disk read time)
- Write_time (disk write time)
Psutil.disk_io_counters () How to use:
#import psutil#psutil.disk_partitions () # Get disk full information #psutil.disk_usage ('/') # Get partition (parameter) usage #psutil.disk_io_counters () # Get the total IO number, read and write Information #psutil.disk_io_counters (perdisk=true) # ' perdisk=true ' parameter to get a single partition IO number, read and write information
Network information:
The network information mainly includes the following parts:
- Bytes_sent (number of bytes sent)
- Bytes_recv (number of bytes received)
- Packets_sent (number of packets sent)
- PACKETS_RECV (number of packets received)
Psutil.net_io_counters () How to use:
#import psutil#psutil.net_io_counters () # Get network total IO information, default pernic=false#psutil.net_io_counters (pernic=true) # Output IO information for each network interface
Additional System Information:
#import psutil,datetime#psutil.users () # Returns the user information for the currently logged on System #psutil.boot_time () # Gets the boot time, returned in the Linux timestamp format # Datetime.datetime.formtimestamp (Psutil.boot_time ()). Strftime ('%y-%m-%d%h:%m:%s ') # Convert to Natural time format
Python automated Operations-system Performance Information module