#coding:utf-8import threadingfrom datetime import datetimeimport timeimport osimport smtplib#from email.mime.text import MIMETextfrom email.MIMEText import MIMEText#from email.Header import Header#from log import loggerimport logging,os,time,atexit,sysfrom signal import SIGTERMimport subprocessimport socket,fcntl,structdef write_log(local_logs):if not os.path.exists("disklogs"):try:os.mkdir("disklogs")except:print 'can not mkdir'cur_time = time.strftime("%Y%m%d")logs = "["+time.strftime("%Y-%m-%d-%H-%M-%S")+"]: "+local_logs+"\n"file = open("disklogs/"+cur_time+".txt","a")file.write(logs)file.close()def disk_stat():hd = {}disk = os.statvfs("/data")free = (disk.f_bavail * disk.f_frsize)total =(disk.f_blocks * disk.f_frsize)used = (disk.f_blocks - disk.f_bfree) * disk.f_frsize*1.024try:percent = (float(used) / total) * 100except error:# get_log().info('calucate error')passreturn percentdef get_log():logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',datefmt='%a, %d %b %Y %H:%M:%S',filename='myapp.log',filemode='w')logger = logging.getLogger(&
用python监控磁盘_python进行磁盘监控 处理 和 报警
最新推荐文章于 2024-03-30 17:57:24 发布