1. 程式人生 > >CPU負載監控

CPU負載監控

encoding pri print out odin close pos popen IT

#!/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)

CPU負載監控