Python automated O & M-system performance information module, python system performance
Module: psutil
Psutil is a cross-platform database that allows you to easily obtain information about processes and resource utilization of the system.
Function: mainly for 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:
Psutil. cpu_times () usage:
# Import psutil # psutil. cpu_times (percpu = True) # Use the cpu_times method to obtain complete CPU information. All logical CPU information must be displayed. percpu = True (optional) # psutil. cpu_times (). user # obtain individual data information, such as the CPU time ratio of the user # psutil. cpu_count () # obtain the number of CPU logic. The default value is logical = True # psytil. cpu_count (logical = False) # obtain the physical number of CPUs
Memory information:
The memory information mainly includes the following parts:
Psutil. virtual_memory () and psutil. swap_memory () usage:
# Import psutil # mem = psutil. virtual_memory () # obtain the complete memory information # print (mem) # mem. total # retrieve the total memory # mem. free # obtain the number of idle memory # psutil. swap_memory () # obtain swap partition information
Disk information:
The disk information mainly includes the following parts:
Psutil. disk_io_counters () usage:
# Import psutil # psutil. disk_partitions () # obtain the complete disk information # psutil. disk_usage ('/') # obtain partition (parameter) usage # psutil. disk_io_counters () # obtain the total I/O count and read/write information of the hard disk # psutil. disk_io_counters (perdisk = True) # The 'perdisk = true' parameter obtains the IO count and read/write information of a single partition.
Network Information:
The network information mainly includes the following parts:
Psutil.net _ io_counters () usage:
# Import psutil # psutil.net _ io_counters () # obtain the total IO information of the network. The default value is pernic = False # psutil.net _ io_counters (pernic = True) # output the IO information of each network interface
Other System Information:
# Import psutil, datetime # psutil. users () # Return the user information of the current logon system # psutil. boot_time () # obtain the boot time, which is returned in the Linux timestamp format # datetime. datetime. formtimestamp (psutil. boot_time ()). strftime ('% Y-% m-% d % H: % M: % s') # convert to natural time format