This article and later articles on Python operations are reading notes forPython automated operations: technology and best Practices .
Psutil is a third-party library of Python that makes it easy to get a variety of information about the system running: CPU, memory, disk, network, etc.
An installation
Installation environment is CentOS 6.4 64-bit system
Yum install-y gcc python-develwget https://pypi.python.org/packages/source/p/psutil/psutil-2.0.0.tar.gz-- NO-CHECK-CERTIFICATETAR-ZXVF psutil-2.0.0.tar.gz CD Psutil-2.0.0python setup.py install
Two Get System Information
(1) CPU information
The CPU utilization of the Linux operating system has 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 due to IO waits
Idle, percentage of time that the CPU is in idle state
Import Psutilpsutil.cpu_times () #使用cpu_times method Get CPU Complete information scputimes (user=3.1099999999999999, nice=0.0, system=11.25, idle=650.85000000000002, iowait=6.4199999999999999, irq=0.26000000000000001, softirq=0.57999999999999996, steal= 0.0, guest=0.0) psutil.cpu_times (). User #获取用户 user CPU time ratio result: 3.25
(2) Memory information
Mem=psutil.virtual_memory () #使用psutil. Virtual_memory method Get memory Full information Memsvmem (total=1036849152l, available=911863808l, percent=12.1, used=230907904l, free=805941248l, active=56578048, inactive=81563648, buffers=18456576l, cached= 87465984)
This article is from the "Silent Learning" blog, please be sure to keep this source http://mzs0207.blog.51cto.com/1874062/1580646
Python gets Linux system performance information