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

Linux网络实时监控配置的更多相关文章

  1. 搭建属于你的家庭网络实时监控–HTML5在嵌入式系统中的应用·高级篇

    *本文已刊登在<无线电>2014年第6期 <搭建属于你的在线实时採集系统>中已经对HTML5平台有了初步的认识,并基于此向大家展示了怎样将採集到的数据上传至网络.实现实时观測. ...

  2. Linux 系统实时监控的瑞士军刀 —— Glances

    Linux 系统实时监控的瑞士军刀 —— Glances 对于 RHEL/CentOS/Fedora 发行版 ## RHEL/CentOS 7 64-Bit ## # wget http://dl.f ...

  3. 需要了解的 Linux 网络和监控命令

    列出来的10个基础的每个linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nslookup ...

  4. 10个基础的linux网络和监控命令

    配置zookeeper集群时,需要查看本机ip,输入命令 hostname -i   就会只显示主机ip, 下边搜了一篇常用的    命令,闲的时候多敲敲命令,以便用的时候再找! 我下面列出来的10个 ...

  5. 注意啦!10 个你需要了解的 Linux 网络和监控命令

    下面列出来的10个基础的每个Linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些:hostname, ping, ifconfig, iwconfig, netstat, nslooku ...

  6. 10个实用的 Linux 网络和监控命令[转]

    本文列出了10个基础的每个Linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nslooku ...

  7. 10个linux网络和监控命令

    我下面列出来的10个基础的每个linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nsloo ...

  8. 10 个你需要了解的 Linux 网络和监控命令

    我下面列出来的10个基础的每个linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nsloo ...

  9. 基于操作系统的Linux网络参数的配置

    一.实验目的 1.掌握Linux下网络参数的查看方法并理解网络参数的含义. 2.掌握Linux下网络参数的配置 二.实验内容 1.查看当前网络配置的参数. 2.在Linux主机中将网络参数按以下要求设 ...

随机推荐

  1. JSP中的TAG文件和TLD文件小结

    在jsp文件中,可以引用tag和tld文件. 1.对于tag文件 <%@ taglib prefix="ui" tagdir="/WEB-INF/tags" ...

  2. Node.js umei图片批量下载Node.js爬虫1.00

    这个爬虫在abaike爬虫的基础上改改图片路径和下一页路径就出来了,代码如下: //====================================================== // ...

  3. 修改PHP上传文件的大小限制

    Warning: POST Content-Length of 35052172 bytes exceeds the limit of 8388608 bytes in Unknown on line ...

  4. 对PHP中类、继承、抽象的理解(个人总结)

    1,PHP中的类可以被继承:A extends B. 2,类被声明为abstract时:a.该类就仅仅包含模版,我们就不能创建该类的实例对象,必须通过继承来使用new创建对象. b.继承一个抽象类的时 ...

  5. qq邮箱、qq空间点击后以word方式打开解决办法

    解决办法: Internet--工具--Internet选项--程序--设为默认值

  6. Struts2-Spring和Hibernate整合

    Struts作为MVC 2的Web框架,自推出以来不断受到开发者的追捧,得到广泛的应用.作为最成功的Web框架,Struts自然拥有众多的优点:MVC 2模型的使用.功能齐全的标志库(Tag Libr ...

  7. 使用PHP和GZip压缩网站JS/CSS文件加速网站访问速度

    使用PHP和GZip压缩网站JS/CSS文件加速网站访问速度 一些泛WEB 2.0网站为了追求用户体验,可能会大量使用CSS和JS文件.这就导致在服务器带宽一定的情况下,多用户并发访问速度变慢.如何加 ...

  8. es6 对象简化写法-函数

    表达式还可以用于定义方法名. let obj = { ['h' + 'ello']() { return 'hi'; } }; obj.hello() // hi

  9. 从cocos2dx到cocos2dhtml5的不同之处

    首先cocos2dhtml5使用javascript编程, 严格区分大写和小写. 1.新建cocos2dhtml5项目. 直接复制引擎自带的helloworld.改一下目录名字就可以. 2.新增js文 ...

  10. 【VBA编程】02.调试VBA程序

    初次编写程序并不一定能成功的运行,可能其中还存在逻辑上或语法上的错误,此时就需要逐步调试,排查错误,一般情况下,编写程序的工作讲究的是三分编程,七分调试. [代码区域] Sub Second() Di ...