[root@swarm-213 ~]# cat systemissue.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # @Time : 2018-12-17 17:16 # @Author : opsonly # @Site : # @File : systemissue.py # @Software: PyCharm import psutil def memissue(): print('内存信息:') mem = psutil.virtual_memory() # 单位换算为MB memtotal = mem.total/1024/1024 memused = mem.used/1024/1024 print('已用内存:%.2fMB' % memused) print('全部内存:%.2fMB' % memtotal) print('内存使用率:{:.2%}'.format(mem.used/mem.total)) def disklist(): print('磁盘信息:') disk = psutil.disk_partitions() diskuse = psutil.disk_usage('/') #单位换算为GB diskused = diskuse.used / 1024 / 1024 / 1024 disktotal = diskuse.total / 1024 / 1024 / 1024 diskbaifen = diskused / disktotal * 100 print('硬盘使用:%.2fGB' % diskused) print('硬盘总大小:%.2fGB' % disktotal) print('硬盘使用率:%.2f' % diskbaifen) print('硬盘剩余率:%.2f' % diskuse.percent) memissue() print('*******************') disklist()