安装python模块psutil

进去linux主机 安装IPy模块

git clone https://github.com/haypo/python-ipy.git

cd python-ipy

python setup.py install

 

安装psutil模块,可以通过python获取系统的cpu,磁盘,内存,进程,网络等相关信息

下载地址https://pypi.python.org/pypi/psutil/

tar -zxvf psutil-2.1.3.tar.gz

cd psutil-2.1.3

 python setup.py install

安装是出现报错

error: command 'gcc' failed with exit status 1

解决办法

yum install gcc python-devel

重新安装

 python setup.py install

安装成功

 

运行的一些实例

>>> import psutil
>>> psutil.cpu_times()
scputimes(user=19207.82, nice=88.010000000000005, system=31732.639999999999, idle=20690363.170000002, iowait=1414.04, irq=543.19000000000005, softirq=463.97000000000003, steal=0.0, guest=0.0)
>>> psutil.cpu_time().user
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>>  psutil.cpu_time() .user
  File "<stdin>", line 1
    psutil.cpu_time() .user
    ^
IndentationError: unexpected indent
>>> psutil.cpu_time().root
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>>  psutil.cpu_count()
  File "<stdin>", line 1
    psutil.cpu_count()
    ^
IndentationError: unexpected indent
>>> psutil.cpu_count()
4
>>> psutil.cpu_count()
4
>>>  psutil.cpu_count()
  File "<stdin>", line 1
    psutil.cpu_count()
    ^
IndentationError: unexpected indent
>>> psutil.cpu_time().user
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_time() .user
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_time()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_times().user
19208.419999999998
>>>  psutil.cpu_count(logical=false)
  File "<stdin>", line 1
    psutil.cpu_count(logical=false)
    ^
IndentationError: unexpected indent
>>> psutil.cpu_count(logical=False)
2
>>> mem=psutil.virtual_memory()
>>> mem
svmem(total=8256098304L, available=2370256896L, percent=71.299999999999997, used=8012435456L, free=243662848L, active=1199607808, inactive=1128972288, buffers=274292736L, cached=1852301312)
>>> mem.total
8256098304L
>>> mem.free
243662848L
>>>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值