检查系统磁盘和内存使用情况
#!/usr/bin/python2.7 # -*- coding: utf-8 -*- # @Time: 2019年8月14日 # @Author: trent # 安装以下依赖工具 # python 2.7.5 # python-devel # psutil-2.1.3 import psutil def memissue(): print('memory info: ') mem = psutil.virtual_memory() # 单位换算为MB memtotal = float(mem.total/1024/1024) memused = float(mem.used/1024/1024) membaifen = memused/memtotal*100 print('%.2fMB' % memused) print('%.2fMB' % memtotal) print('memory usage percent: %.2f' % membaifen + '%') def disklist(): print('disk info: ') disk = psutil.disk_partitions() diskuse = psutil.disk_usage('/') #单位换算为GB diskused = float(diskuse.used / 1024 / 1024 / 1024) disktotal = float(diskuse.total / 1024 / 1024 / 1024) diskbaifen = diskused / disktotal * 100 print('%.2fGB' % diskused) print('%.2fGB' % disktotal) print('disk usage percent: %.2f' % diskbaifen + '%') memissue() print('*******************') disklist()