赞
踩
#!/usr/bin/python
#coding:utf-8
import commands
import os
import re
import datetime
#if mem util > 30 echo to mem_file_report and cpu util
mem_info = commands.getstatusoutput(‘top -b|head -n30|tail -n24‘)
info = mem_info[1].split(‘\n‘)
count = 0
num = 0
for i in info:
if count == 0:
global header
header = i
if count >= 1:
i_list = i.split()
num_mem = i_list[9].split(‘.‘)[0]
num_cpu = i_list[8].split(‘.‘)[0]
if int(num_mem) >= 40 or int(num_cpu) >= 50:
with open(‘/opt/scripts/mem_cpu_tcp_check.log‘,‘a‘) as f:
result = "%s %s"%(datetime.datetime.now(),i)
f.write(result + ‘\n‘)
num+=1
if count >= 23 and num >= 1:
with open(‘/opt/scripts/mem_cpu_tcp_check.log‘,‘a‘) as f:
result1 = "%s %s"%(datetime.datetime.now(),header)
f.write(‘\n‘ + result1 + ‘\n‘ + ‘=========================================================‘ + ‘\n‘)
count+=1
#tcp 连接信息详情
tcp_num = commands.getstatusoutput("netstat -antupl|grep ESTABLISHED|wc -l")
#print tcp_num[1]
tcp_info = commands.getstatusoutput("netstat -antupl|grep ESTABLISHED")
if int(tcp_num[1]) >= 100:
with open(‘/opt/scripts/tcp_check.log‘,‘a‘) as f:
f.write(‘\n‘ + "============================================================" + ‘\n‘ + str(datetime.datetime.now()) + ‘\n‘ + tcp_info[1])
interface liuliang warning
liuliang = commands.getstatusoutput("iftop -i eth0 -N -P -t -L 50 -s 10")
#liuliang_list = liuliang[1].split(‘\n‘)
#print liuliang[1]
#for i in liuliang_list:
new_num = i.split()[4]
new_num1 = re.findall(r‘\d+‘,new_num)[0]
print new_num1
if int(new_num1) == 0:
liuliang_list.remove(i)
#print ‘\n‘.join(liuliang_list)
receive = liuliang[1].split(‘\n‘)[-7].split()[5]
send = liuliang[1].split(‘\n‘)[-6].split()[5]
#print liuliang[1].split(‘\n‘)[-7].split()[5]
#print liuliang[1].split(‘\n‘)[-6].split()[5]
receive_type = re.findall("Kb|Mb|Gb",receive)[0]
send_type = re.findall("Kb|Mb|Gb",send)[0]
#print re.findall(r‘\d+‘,receive)
#print re.findall(r‘\d+‘,send)
receive_num = re.findall(r‘\d+‘,receive)[0]
send_num = re.findall(r‘\d+‘,send)[0]
if receive_type == "Mb" and send_type == "Mb":
if int(receive_num) >= 40 and int(send_num) >= 40:
with open(‘/opt/scripts/iftop.log‘,‘a‘) as f:
result1 = "%s %s"%(datetime.datetime.now(),header)
time_now = str(datetime.datetime.now())
f.write(‘\n‘ + ‘=========================================================‘ + ‘\n‘ + time_now + ‘\n‘ + liuliang[1])
if receive_type == "Gb" and send_type == "Gb":with open(‘/opt/scripts/iftop.log‘,‘a‘) as f:result1 = "%s %s"%(datetime.datetime.now(),header)time_now = str(datetime.datetime.now())f.write(‘\n‘ + ‘=========================================================‘ + ‘\n‘ + time_now + ‘\n‘ + liuliang[1])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。