程序员的资源宝库

网站首页 > gitee 正文

系统内存与磁盘检测(内存或磁盘空间)

sanyeah 2024-04-01 11:26:38 gitee 5 ℃ 0 评论

[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('硬盘使用率:{:.2%}'.format(diskbaifen/100))
    print('硬盘剩余率:{:.2%}'.format(diskuse.percent/100))


memissue()
print('*******************')
disklist()

 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表