Notes on python System Performance module and python System Performance module

Source: Internet
Author: User

Notes on python System Performance module and python System Performance module

Memory Information
Psutil. cpu_times () use the cpu_times method to obtain complete cpu information. All logical cpu information must be displayed (the variable percpu = True)
Psutil. cpu_times (). The user obtains individual data information, such as the cpu time ratio of the user.
Psutil. cpu_count () to obtain the number of cpu logic. The default value is logical = True4.
Psutil. cpu_count (logical = False) to obtain the cpu physical information

Disk Information
Psutil. disk_partitions () Use psutil. disk_partitions to obtain complete disk Information
Psutil. disk_usage ('/') use the psutil. disk_usage method to obtain partition (parameter) Usage
Psutil. disk_io_counters () Use psutil. disk_io_counters to obtain the number of I/O instances on the hard disk.
Psutil. disk_io_counters (perdisk = True) perdisk = True. The parameter obtains the IO count of a single partition.

Network Information
Psutil.net _ io_counters () Use Psutil.net _ io_counters to obtain the IO information in the network. The default value is pernic = False. If True, the IO information of each network structure is output.

Other System Information
Psutil. users () returns the user information of the current logon system using the psutil. users Method
Psutil. boot_time () use the psutil. boot_time method to obtain the boot time, which is returned in the Linux timestamp format.
Import psutil, datetime. datetime. fromtimestamp (psutil. boot_time ()). strftime ("% Y-% m-% d % H: % M: % S") is converted to the natural time format

System Process Management

Psutil. pids () lists the PID of all processes
Psutil. Process (*) instantiate a Process object. The parameter is a Process PID.
P = pstuil. Process ()

P. name () process name
P.exe () is a binning process, and p.exe is used in windows.
The absolute path of the p. cwd () process working directory. The path is p and cwd in win.
P. status () Process status
P. create_time () Process Creation Time, timestamp format
Uid information of p. uids () Process
P. gids () process gid Information
P. cpu_affinity () get process cpu affinity. To set the process cpu affinity, use the cpu number as the parameter.
P. momory_info () process memory utilization
P. io_counters () process IO information, including the number of read/write IO and the number of bytes
P. connections () returns the namedutples list for enabling the process socket, including the fs, family, and laddr information.
P. num_threads () Number of threads enabled by the Process

From subprocess import PIPE
P = psutil. popen (["/usr/bin/python", "-c", "print ('hello')", stdout = PIPE]) applications started using the psutil Popen method can trace all information about the program running.
P. name () 'python'
P. username () 'root'
P. coummunicate () ('Hello \ n', None)
P. cpu_times () Get the cpu running time of the process



IPy
IP address processing module
IP ('1970. 100'). version () returns IPv4 type
IP (': 1'). version () returns the IPv6 Type
Ip = IP ('1970. 168.1.1 ')
Ip. reverseNames () reverse resolution address format
Ip. iptype () 192.168.1.1 is
Ip.int () to integer format
Convert ip. strHex () to hexadecimal
Convert ip. strBin () to binary
Ip. netmask () Subnet Mask
Ip.net () Output network address
Ip. broadcast () Output network broadcast address

Print (IP (ox8080808) hexadecimal conversion to IP Format
IP address and mask production CIDR block format
Print (IP ('1970. 168.1.0 '). make_net ('1970. 255.255.0 '))
Print (IP ('1970. 168.1.0/255.255.255.0 ', make_net = True ))
Print (IP ('1970. 168.1.0-192.168.1.255 ', make_net = True ))
IP ('100. 192. 168.1.0/24 '). strNormal (*) wantprefixlen Parameter definition. 0: none are returned, for example, 192.168.1.0; 1: prefix format: 192.168.1.0, 24; 2: decimalnetmask format: 192.168.1.0, 255.255.255.0; 3: lastIP format: 192.168.1.0-192.168.1.255

Multi-Network Computing Method
IP ('10. 0.0./24') <IP ('12. 0.0.0/24') True
'192. 168.1.100' in IP ('192. 168.1.0/24') True
IP ('1970. 168.1.0/24') in IP ('1970. 168.0.0/16') Ture
IP ('192. 168.0.0/23'). overlaps ('192. 168.1.0/24'). If the return value is 1, the return value is heavy. If the return value is 0, the IP address does not overlap.

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.