installation is simplePip Install Psutil
Website address is https://pythonhosted.org/psutil/(detailed API on document) GitHub address is https://github.com/giampaolo/psutil/
Psutil better Place, one is cross-platform, do not need to switch the platform when the re-open,Another benefit of the toolset is the CPU, memory, disks, network, all of which can be obtained. Can be used to do system monitoring, performance analysis, process management. The systems that can be supported areLinux, Windows, OSX, FreeBSD and Sun solaris,32 and 64-bit systems all support, while supporting pyhton2.4 to 3.4.
To see how good cross-platform is, under Windows Labs
#-*-coding:utf-8-*-#python2.7x#author: [email protected] 2014-12-12#psutiltest.py "Follow the tutorial for a simple study of the use of Psutil, Windows Try "Import psutilimport datetime# view CPU Information print U" CPU number%s "%psutil.cpu_count () print U" physical CPU number%s "%psutil.cpu _count (logical=false) print U "CPU uptimes" Print psutil.cpu_times () print "" #查看内存信息print U "System total memory%s M"% (psutil. total_phymem/1024/1024) Print U "System available memory%s M"% (Psutil.avail_phymem ()/1024/1024) mem_rate = Int (Psutil.avail_phymem ())/ Float (psutil. TOTAL_PHYMEM) Print U "system memory utilization%s percent"%int (mem_rate*100) #系统启动时间print u "System boot time%s"%datetime.datetime.fromtimestamp ( Psutil.boot_time ()). Strftime ("%y-%m-%d%h:%m:%s") #系统用户users_count = Len (Psutil.users ()) Users_list = ",". Join ([ U.name for u in Psutil.users ()]) print U "currently has%s users, respectively%s"% (Users_count, users_list) #网卡, 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_sent/1024) Print U "network card receive traffic%s network card send traffic%s"% (BYTES_RCVD, bytes_sent) #进程 the various detailed parameters of the process # magneticDisk usage, and so on.
from this simple case, it can be seen that Psuti is powerful, so it works well on window, and it is very suitable for system data collection.
Please refer to the official documentation for details if you need to use it. There are also some code snippets on gist to refer to Https://gist.github.com/search?q=psutil
This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41891447
Author Orangleliu using Attribution-NonCommercial-sharing protocol in the same way
[Python monitoring]psutil module simple to use