Python Psutil for System Management

Source: Internet
Author: User

    • First you need to install the Psutil package

      1   wget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz-- No-check-certificate2   tar -zxvf psutil-2.0.  0. Tar . GZ 3   CD psutil-2.0. 0 4   Install

The installation is complete, and the Python version here is 3.4

    • Reference Psutil

      1 Import Psutil

    • CPU utilization

The CPU utilization of the Linux operating system has the following parts:

User Time,执行用户进程的时间百分比;* System Time,执行内核进程和中断的时间百分比;* Wait IO,由于 IO 等待而使 CPU 处于 idle(空闲)状态的时间百分比;* Idle,CPU 处于 idle 状态的时间百分比
1 Import Psutil 2 psutil.cpu_times ()  # Use the Cpu_times method to get full CPU information, need to display all the logical CPU information, specify the method variable percpu=true, such as Psutil.cpu_time S (percpu=True)3psutil.cpu_times (). User # Gets individual data information, such as the user's CPU time compared to 4 psutil.cpu_ Count () # Gets the logical number of CPUs, default logical=True45 psutil.cpu_count (logical=false) # Gets the physical number of CPUs

 
  • Memory parameter

     1  mem = Psutil.virtual_ Memory () # Use the Psutil.virtual_memory method to get the full information of the Ram  2   Mem.total # gets total memory  3  mem. free   # Get free memory number  4  psutil.swap_memory () # Get swap partition information 

     

  • Disk information

    1   psutil.disk_partitions () # Get disk full information using the Psutil.disk_partitions method 2   psutil.disk_usage (  '/') # Use the Psutil.disk_usage method to get the partition (parameter) usage 3  Psutil.disk_io_ Counters () # Use Psutil.disk_io_counters to get the total IO number of the drive 4   psutil.disk_io_counters (perdisk=true) # " Perdisk=true "parameter gets the number of single partition IO

* Network Information

1     Psutil.net_io_counters () # Use Psutil.net_io_counters to get the total IO information of the network, default pernic=False2     psutil.net_ Io_counters (pernic=true) #pernic =true output IO information for each network interface

    • Other System Information

      1 psutil.users () # Use the Psutil.users method to return user information for the currently logged on system

Python Psutil for System Management

Related Article

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.