Python-psutil Module

Source: Internet
Author: User

The Psutil is a cross-platform library that makes it easy to get the process and system utilization information for the system running. It is mainly used for system monitoring, analyzing and restricting system resources and process management. It implements the functions provided by the equivalent command line tools, such as PS, top, lsof, netstat, etc... Usually we get the operating system information often implemented by writing a shell, such as getting the total size of physical memory and already used size, the shell command is as follows:

See how the Psutil module using Python implements

8bit (bit) =1byte (bytes)
1024Byte (bytes) =1kb
1024kb=1mb
1024mb=1gb
1024gb=1tb

Get System Performance Information
The basic performance information of the acquisition system includes CPU, memory, disk, network and so on, which can describe the running state and quality of the current system completely.
1. Collecting CPU Information
You can use the Psutil.cpu_times () method to get this information very simply, as well as to obtain hardware-related information about the CPU, such as the number of physical and logical CPUs, such as:

2. Collect Memory information
The memory utilization information of the Linux system relates to total (amount of memory), used (number of memory used), free (number of idle memory), buffer (buffer usage), cache (number of cached uses), swap (swap partition usage), etc. Information can be obtained using the psutil.virtual_memory () and the Psutil.swap_memory () method, respectively, for example:

3. Collecting disk information
Of all the disk information in the system, we are concerned with disk utilization and IO information, where disk utilization is obtained using the Psutil.disk_usage method. Disk IO information includes read_count (read IO), write_count (write io number), read_bytes (io read bytes), write_bytes (io write bytes), read_time (disk read time), Write_ Time (disk write times), etc., this information can be obtained through psutil.disk_io_counters ().

4. Network Information
The network information of the system is similar to disk IO, involving several key points, including bytes_sent (number of bytes sent), bytes_recv (number of bytes received), Packets_sent (number of packets sent), PACKETS_RECV (number of packets received), etc. These network information is obtained using the Psutil.net_io_counters () method.

5, access to user login, boot time and other information

6, the system process management methods
Obtaining process information for the current system allows us to know the running state of the application, including the start time of the process, the viewing or setting of CPU affinity, memory usage, IO information, socket connection, number of threads, which can present the specified process for survival and resource utilization.

7, the use of Popen class
The purpose of the Popen class provided by Psutil is to obtain user-initiated application process information in order to track the running state of the program process.

Python-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.