Python gets Linux system performance information

Source: Internet
Author: User

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

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.