加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

nmon监控脚本

发布时间:2020-12-15 07:12:09 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/bin/sh###################################################################################FileName:nmon_monitor.sh#Author:Defias#Date2014-

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

#!/bin/sh
##################################################################################
#FileName:	nmon_monitor.sh
#Author:	Defias
#Date	2014-12-2
#example:./nmon.sh -m 30   ./nmon.sh -h 1     ./
##################################################################################

nmonpage_name="nmon_linux_14i.tar.gz"
nmon_name="nmon_x86_64_rhel54"


usage()
{
    echo "usage: $0 -m|-h  minute|hour"
}






check_pid()
{
#进程检查
nmonpid=`ps -ef | grep  ${nmon_name} | grep -v grep | awk '{print $2}'`
#echo "nmonpid is ${nmonpid}"
if [ -n "${nmonpid}" ];then
	echo "process nmon is running!"
        echo "kill process nmon? y/n"
	while true
	do
		read x
		case "$x" in
			y | yes | Y | Yes | YES)
				kill -9 $nmonpid
				if [ $? != 0 ];then
				    echo "kill -9 $nmonpid fail!"
				    exit -1
				fi
				#echo "kill -9 $nmonpid success!"
                                break
				;;
			n | no | N | No | NO)
				echo "nothing to do!"
				exit -1
				;;
			*) 
				echo "Please enter yes or no"
				;;
		esac
	done
fi
}


#参数检查
if [ $# -ne 2 ];then
    usage
    exit 1
fi

opt="$1"
optdata="$2" 

if [ ! ${optdata} -eq ${optdata} ]; then
	echo "$optdata is not a number"  
	usage
	exit 1
fi


#进程检查
check_pid


#包解压
if [ ! -f $nmonpage_name ];then
	echo "don't find $nmonpage_name file! "
	exit 1
fi
chmod 775 $nmonpage_name

pwdpath=`pwd`
if [ ! -d ${pwdpath}/bin ];then
   mkdir ${pwdpath}/bin
fi
nmonpath="${pwdpath}/bin/"

if [ ! -d ${pwdpath}/logs ];then
   mkdir ${pwdpath}/logs
fi
logpath="${pwdpath}/logs/"

tar -zxvf $nmonpage_name -C $nmonpath > /dev/null


#启动nmon监控
case  "$opt"  in
-m)
	if [ $optdata -le 60 ];then
	   ntime=$((${optdata} * 60 / 2))
	   ${nmonpath}${nmon_name} -fT -s 2 -c $ntime -m $logpath
	elif [ $optdata -le 600 ];then
	    ntime=$((${optdata} * 60 / 5))
	    ${nmonpath}${nmon_name} -fT -s 5 -c $ntime -m $logpath
	elif [ ${optdata} -le 1440 ];then
	    ntime=$((${optdata} * 60 / 10))
	    ${nmonpath}${nmon_name} -fT -s 10 -c $ntime -m $logpath
	else 
	    ntime=$((${optdata} * 60 / 15))
	    ${nmonpath}${nmon_name} -fT -s 15 -c $ntime -m $logpath
        fi
        echo "nmon monitor success!"
;;

-h) 
	if [ $optdata -le 1 ];then
	    ntime=$((${optdata} * 60 * 60 / 2))
	    ${nmonpath}${nmon_name} -fT -s 2 -c $ntime -m $logpath
	elif [ $optdata -le 10 ];then
	    ntime=$((${optdata} * 60 * 60 / 5))
	    ${nmonpath}${nmon_name} -fT -s 5 -c $ntime -m $logpath
	elif [ ${optdata} -le 24 ];then
	    ntime=$((${optdata} * 60 * 60 / 10))
	    ${nmonpath}${nmon_name} -fT -s 10 -c $ntime -m $logpath
	else 
	    ntime=$((${optdata} * 60 * 60 / 15))
	    ${nmonpath}${nmon_name} -fT -s 15 -c $ntime -m $logpath  
        fi	
        echo "nmon monitor success!"
;;
*)
	echo "$opt is error!"
	usage
;;
esac

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读