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. CentOS7 下安装 Lnmp 架设 Laravel

    最近在hostos上买了个香港的 vps, 装的 centos7, 在架设了 pptp vpn, 效果还行,就想顺便架设个 laravel 看看.下面是架设的过程.准备工作 更新 yum 源,自带的源 ...

  2. ckeditor 前段js配置toolbar以及取值(实用)

    <%@ page contentType="text/html;charset=UTF-8"%><%@ include file="/WEB-INF/v ...

  3. BEA公司的weblogic是什么?有什么特点?

    转自:http://zhidao.baidu.com/link?url=J9obKwHhuh1sdLoBC3pILeaq1nz_tcpScggBNeS3D0GzAz9FI002vlS2xxJD4_z6 ...

  4. ASP.NET MVC & Web API Brief Introduction

    Pure Web Service(ASMX): Starting back in 2002 with the original release of .NET, a developer could f ...

  5. 演示程序之打游戏 -- 慕司板IAP15

    上位机和协议制定我的大学舍友(他的微博:http://weibo.com/lesshst? topnav=1&wvr=5&topsug=1)毕业前百忙之中使用Python花了一个下午完 ...

  6. Unity3D Gamecenter 得分上传失败的处理

    Unity3DGamecenter 得分上传失败的处理. 常常会有种情况是,玩家在地铁或者飞机上没法通过wifi或者3G连接到服务器,从而会导致上传分数失败 解决方法: 这时候需要把得分存在Playe ...

  7. 2 自己编写:AppDelegate,CCApplication,CCApplicationProtocol

    1 CCApplicationProtocol.h /* * CCApplicationProtocol.h * *  Created on: 2014年10月19日 *      Author: t ...

  8. js操作当前窗口

      CreateTime--2017年7月21日09:58:34Author:Marydon js操作当前窗口 1.打开一个新的窗口(新的标签页) 实现方式:window.open(url) 实例一: ...

  9. JDBC:数据库操作:处理大对象CLOB数据

    目标: 了解大对象处理基本原理, 掌握CLOB数据的读,写操作. 可以使用CLOB类处理大文本数据. 大对象处理主要指CLOB和BLOB两种类型字段.可以大量存储文字. 要想在程序中处理这样的大数据操 ...

  10. hibernate 一对多双向的CURD

    转自尚学堂教学视频   package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import java ...