Python module Psutil Use--Get the System state

Source: Internet
Author: User
Tags disk usage

First, installation

This time, using Python under win7, download the installation package directly to complete the installation. Many of the links on the Internet can not find resources, took some effort, finally found the available links.

64-bit:

Https://pypi.python.org/packages/2.7/p/psutil/psutil-3.2.1.win-amd64-py2.7.exe#md5= 272e5654143ab40ad503e95496ae3688

32-bit:

Https://pypi.python.org/packages/2.7/p/psutil/psutil-3.2.1.win32-py2.7.exe#md5= 151f8ae32aaa086f37d13bd62dcca348

Second, use

#-*-coding:utf-8-*-ImportPsutilImportdatetime" "#查看cpu的信息 Print U "CPU Count%s"%psutil.cpu_count () Print U "Physical CPU Count%s"%psutil.cpu_count (logical=false) print U "CPU u Ptimes "Print psutil.cpu_times () print" "#查看内存信息 # Print U" System total memory%s M "% (psutil. total_phymem/1024/1024) # print U "System free memory%s M"% (Psutil.avail_phymem ()/1024/1024) # mem_rate = Int (Psutil.avail_phymem () )/float (Psutil. TOTAL_PHYMEM) # Print U "system memory usage%s percent"%int (mem_rate*100) #系统启动时间 print U "system boot time%s"%datetime.datetime.fromtimestamp (p Sutil.boot_time ()). Strftime ("%y-%m-%d%h:%m:%s") #系统用户 Users_count = Len (Psutil.users ()) Users_list = ",". Join ([u.na Me for U in Psutil.users ()) Print U "currently has%s users, respectively%s"% (Users_count, users_list) #网卡, you can get network card properties, connections, current traffic and other information net = Psutil. Net_io_counters () Bytes_sent = ' {0:.2f} KB '. Format (net.bytes_recv/1024) Bytes_rcvd = ' {0:.2f} KB '. Format (Net.bytes_sen t/1024) Print U "NIC receive traffic%s NIC send traffic%s"% (BYTES_RCVD, bytes_sent)" "#various detailed parameters of the process process#View all system processesPrintU"system All process%s"%Psutil.pids () forPnuminchpsutil.pids (): P=Psutil. Process (Pnum)PrintU"Process name%-20s memory Utilization%-18s process state%-10s creation time%-10s"%(P.name (), P.memory_percent (), P.status (), P.create_time ())#print p.io_counters () #进程读写信息#p.cwd () #进程的工作目录绝对路径#p.status () #进程状态#p.create_time () #进程创建时间#p.uids () #进程uid信息#disk disk usage, and so on.

Python module Psutil Use--Get the System state

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.