进去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 "
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_time() .user
File "
psutil.cpu_time() .user
^
IndentationError: unexpected indent
>>> psutil.cpu_time().root
Traceback (most recent call last):
File "
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_count()
File "
psutil.cpu_count()
^
IndentationError: unexpected indent
>>> psutil.cpu_count()
4
>>> psutil.cpu_count()
4
>>> psutil.cpu_count()
File "
psutil.cpu_count()
^
IndentationError: unexpected indent
>>> psutil.cpu_time().user
Traceback (most recent call last):
File "
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_time() .user
Traceback (most recent call last):
File "
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_time()
Traceback (most recent call last):
File "
AttributeError: 'ModuleWrapper' object has no attribute 'cpu_time'
>>> psutil.cpu_times().user
19208.419999999998
>>> psutil.cpu_count(logical=false)
File "
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
>>>