#!/usr/bin/python #-*- encoding: utf-8 -*- import os import time while True: loadavg=os.popen("cat /proc/loadavg | awk ‘{print $1}‘").read().replace(‘\n‘,‘‘)
#负载大于3就做记录 if float(loadavg) >= 3: date=time.strftime("%Y-%m-%dT%H-%M-%S", time.localtime()) data=os.popen("top -b -n 1").read() output = open(‘top-%s.log‘%date, ‘w‘) output.write(data) output.close( ) time.sleep(10)