Linux监控邮件发送配置

网络状态监控

网络状态:netstat 各个状态的总计,详情;以及重点端口的详细连接情况(22,25,80,3306,8080),打印客户端连接数最多的ip。

邮件报告当前状态。

对于每个端口的连接数,自己可以设置阈值,加个if判断就可以完成报检的功能。

在手机上安装网易的邮件客户端,就可以达到实时提醒的效果。

关于mail的配置,见文章:http://blog.csdn.net/rookie_ceo/article/details/46559195

#!/bin/sh
source /etc/profile IP=`/sbin/ifconfig|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p'|grep -v '127.0.0.1'`
warn_pct=1 #75
warn_name=[NET-State]
performance_path=/monitor/performance
mailtmp=/u01/soft/smonitor/mailtmplet/"$warn_name"tmp.mail
infotmp=/u01/soft/smonitor/mailtmplet/"$warn_name"tmp.tmp
maillist=490073687@qq.com,zhou.xiangxing210@163.com DT=`date +"%Y-%m-%d %H:%M:%S"`
netstat -nap > $infotmp
cat $infotmp|grep '^tcp' > $infotmp.tmp stat_help="\n-----------------------------Stat Mean-------------------------------"
stat_help="$stat_help""\n LISTEN:Listening for a connection.侦听来自远方的TCP端口的连接请求"
stat_help="$stat_help""\n\n SYN-SENT:Active; sent SYN. Waiting for a matching connection request after having sent a connection request."
stat_help="$stat_help""\n 再发送连接请求后等待匹配的连接请求."
stat_help="$stat_help""\n\n SYN-RECEIVED:Sent and received SYN. Waiting for a confirming connection request acknowledgment "
stat_help="$stat_help""\n after having both received and sent connection requests.再收到和发送一个连接请求后等待对方对连接请求的确认"
stat_help="$stat_help""\n\n ESTABLISHED:Connection established.代表一个打开的连接"
stat_help="$stat_help""\n\n FIN-WAIT-1:Closed; sent FIN.等待远程TCP连接中断请求,或先前的连接中断请求的确认"
stat_help="$stat_help""\n\n FIN-WAIT-2:Closed; FIN is acknowledged; awaiting FIN.从远程TCP等待连接中断请求"
stat_help="$stat_help""\n\n CLOSE-WAIT:Received FIN; waiting to receive CLOSE.等待从本地用户发来的连接中断请求"
stat_help="$stat_help""\n\n CLOSING:Closed; exchanged FIN; waiting for FIN.等待远程TCP对连接中断的确认"
stat_help="$stat_help""\n\n LAST-ACK:Received FIN and CLOSE; waiting for FIN ACK.等待原来的发向远程TCP的连接中断请求的确认"
stat_help="$stat_help""\n\n TIME-WAIT:In 2 MSL (twice the maximum segment length) quiet wait after close. 等待足够的时间以确保远程TCP接收到连接中断请求的确认"
stat_help="$stat_help""\n\n CLOSED:Connection is closed.没有任何连接状态"
stat_help="$stat_help""\n------------------------------------------------------------" echo "您好:" >$mailtmp
echo -e " [$DT]服务器:$IP 网络连接信息如下。\n总计:" >>$mailtmp
cat $infotmp.tmp|awk '{print $6}'|sort |uniq -c|sort >>$mailtmp
echo "[$DT]详细:">>$mailtmp
cat $infotmp.tmp|awk '{print $7" "$6 }'|sort |uniq -c |sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp #mysql连接数 3306
cat $infotmp.tmp|grep 3306 |grep mysqld|grep -v LISTEN > $infotmp.tmp.3306
mysql_conn=`cat $infotmp.tmp.3306|wc -l`
echo "mysql 3306端口连接数:$mysql_conn" >>$mailtmp
echo "mysql 3306端口每个ip连接数统计如下:" >>$mailtmp
cat $infotmp.tmp.3306|awk '{print $5}'|awk -F ':' '{print $4}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------">>$mailtmp #ssh连接数 22
cat $infotmp.tmp|grep 22 |grep sshd|grep -v LISTEN > $infotmp.tmp.22
ssh_conn=`cat $infotmp.tmp.22|wc -l`
echo "ssh 22端口连接数:$ssh_conn" >>$mailtmp
echo "ssh 22端口每个ip连接数统计如下:" >>$mailtmp
cat $infotmp.tmp.22|awk '{print $5}'|awk -F ':' '{print $1}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp #httpd连接数 80
cat $infotmp.tmp|grep 80 |grep httpd|grep -v LISTEN > $infotmp.tmp.80
httpd_conn=`cat $infotmp.tmp.80|wc -l`
echo "http 80端口连接数:$httpd_conn" >>$mailtmp
echo "http 80端口每个ip连接数统计如下:" >>$mailtmp
cat $infotmp.tmp.80|awk '{print $5}'|awk -F ':' '{print $4}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp #ssh连接数 8080
cat $infotmp.tmp|grep 8080 |grep java|grep -v LISTEN > $infotmp.tmp.8080
apache_conn=`cat $infotmp.tmp.8080|wc -l`
echo "tomcat 8080端口连接数:$apache_conn" >>$mailtmp
echo "tomcat 8080端口每个ip连接数统计如下:" >>$mailtmp
cat $infotmp.tmp.8080|awk '{print $5}'|awk -F ':' '{print $4}'|sort |uniq -c|sort >>$mailtmp
echo "------------------------------------------------------------" >>$mailtmp echo -e "$stat_help">>$mailtmp DT=`date +"%Y-%m-%d %H:%M:%S"`
echo -e "\nBest Wishes! \n------------------------------------ \nCA system Monitor \n$DT" >> $mailtmp cat $mailtmp
#cat $mailtmp| mailx -s "$warn_name[网络监测]:服务器:$IP" $maillist

最新文章

  1. Java程序日志:java.util.logging.Logger类
  2. rest api参数与content-type
  3. httpd服务的安装、配置和关于php留言本网站的搭建
  4. 在C++中实现字符串分割--split
  5. ADIv5.2
  6. C++疑难杂症
  7. Oracle多线程并行使用、关联与指定索引执行
  8. 测试peerdroid示例程序步骤
  9. 隐藏/显示 我的电脑盘符驱动…
  10. ThinkPHP框架下,给jq动态添加的标签添加点击事件移除标签
  11. ExtJs的事件机制Event(学员总结)
  12. oracle死锁模拟
  13. 我从.net转别的语言的遭遇,现在貌似又要回头(一)
  14. xml文件的方式实现动态代理基于SpringAOP
  15. 对网易云音乐参数(params,encSecKey)的分析
  16. 移动端开发调试工具神器--Weinre使用方法
  17. 数据库范式:1NF,2NF,3NF,BCNF浅析
  18. Django-model基础
  19. java8集合--LinkedList纯源码
  20. SSM项目开发中的实体定义以及MySQL表格设计

热门文章

  1. Java小案例-(逃离迷宫)
  2. Mapreduce报错:java.lang.ClassNotFoundException: Class Mapper not found
  3. Android-标题状态栏的隐藏
  4. 分析apache日志,统计ip访问频次命令
  5. 使用iOS-QR-Code-Encoder 生成二维码
  6. Activity生命周期以及启动模式对生命周期的影响
  7. webDriver API——第7部分Desired Capabilities
  8. Android 开发之使用Eclipse Debug调试详解(转)
  9. 【DB2】判断连续时间,如果间断则新增一条记录
  10. Hadoop生态圈介绍及入门(转)