git clone https://github.com/giampaolo/psutil.git
cd psutil
pip install psutil
import psutil datetime
#cpu实例化
cpu = psutil.cpu_times()
#内存实例化
mem = psutil.virtual_memory()
#虚拟内存
swap = psutil.swap_memory()
#磁盘
disk = psutil.disk_partitions()
#网络
net = psutil.net_io_conunters()
net1 = psutil.net_if_addrs()
实例获取回环IP
>> net1[‘lo‘][0].address
‘127.0.0.1‘
获取本机的IP,我的本机是虚拟机的
>> net1[‘ens3‘][0].address
‘192.168.1.83‘
#系统登录用户信息
uses = psutil.users()
#系统当前时间
date = datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S")
原文地址:http://blog.51cto.com/2687949/2107739