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. linux 遇见错误Could not get lock /var/lib/dpkg/lock

    通过终端安装程序sudo apt-get install xxx时出错:E: Could not get lock /var/lib/dpkg/lock - open (11: Resource te ...

  2. [HTML5] Track First Contentful Paint with PerformanceObserver and Google Analytics

    "If you can't measure it, you can't improve it." The first step when doing performance wor ...

  3. Mach-O文件格式和程序从载入到运行过程

    > 之前深入了解过.过去了一年多的时间.如今花些时间好好总结下,毕竟好记性不如烂笔头. 其次另一个目的,对于mach-o文件结构.关于动态载入信息那个数据区中,命令含义没有深刻掰扯清除,希望有同 ...

  4. 【Firefly API文档】—— Package Netconnect

    http://bbs.gameres.com/forum.php?mod=viewthread&tid=219655 package netconnect 该包中包含的服务端与客户端通信的一些 ...

  5. mui webview操作

    HBuilder的webview操作 webviewAPI文档:http://www.html5plus.org/doc/zh_cn/webview.html 创建新的webview窗口: Webvi ...

  6. [Swift A] - DataSource 与 Delegate有啥区别?

    lukeluke     2012-05-22 07:46 是不是DATASOURCE,提供的是原来对象里并没有的数据,比如,共有几个ITEM啊, 而DELEGATE里,提供的是原来就有的数据,只不过 ...

  7. JBoss目录结构说明

    http://www.blogjava.net/livery/articles/262544.html $JBOSS-HOME/bin:             放置各种脚本文件以及相关文件,包括jb ...

  8. Linxu 监控命令总结

    free –m [root@web1476 ~]# free        total       used       free     shared    buffers     cached M ...

  9. Android View Attributes

    ImageView android:adjustViewBounds  Set this to true if you want the ImageView to adjust its bounds ...

  10. NPOI(2.1.3)向excel中插入图片,xls文档图片插入成功,xlsx文档图片插入失败

    众所周知,NPOI对xls和xlsx两个版本的excel文档的操作并没有一个统一的支持, 程序若想兼容这两个版本的操作,必须根据excel版本分别去调用HSSF和XSSF这两套操作库, 之前一直不明白 ...