编程语言
首页 > 编程语言> > python程序—系统检测

python程序—系统检测

作者:互联网

持续监控系统内存,CPU,硬盘的使用情况,到达阈值时报警

import psutil
import  time
#内存
def meomory_check():
    meom= psutil.virtual_memory()
    if meom[2] >=80.0:
        print('内存已经到达报警阈值!')

#cpu
def cpu_check():
    cpu = psutil.cpu_percent(1)
    if cpu >=80.0:
        print('cpu已经到达报警阈值!')

#硬盘
def disk_check():
    disk = psutil.disk_usage(r'c:')
    if disk[3] >= 80.0:
        print('c盘内存空间已经达到报警阈值!')

while True:
    meomory_check()
    cpu_check()
    disk_check()
    time.sleep(20)

 

标签:80.0,阈值,python,检测,程序,check,psutil,disk,cpu
来源: https://www.cnblogs.com/leeeel/p/10758148.html