免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6632 | 回复: 10
打印 上一主题 下一主题

[求助]如何用shell编写系统性能的监控的脚本!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-07-07 23:30 |只看该作者 |倒序浏览
系统是solaris的,如何用shell实现对系统性能的监控,比如cpu负载,memory,disk的使用情况等动态指标。有哪位高手能详细的介绍下,看到过别人用vmstat,怎么从显示的值来判断系统的性能呢?

论坛徽章:
0
2 [报告]
发表于 2003-07-08 07:01 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

...

直接用  vmstat -w 2 之类的
不就是动态监控了吗  

论坛徽章:
0
3 [报告]
发表于 2003-07-08 09:28 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

while [ 1 ]
do
        echo '                    主机状态实时监控         \c'
        date "+%d/%m/%C%y"
        echo '------------------------------------------------------------------
-------'
        sar -u 1 1
        echo '\n'
        home_err="\c"              

        homedf=`df -v |grep home|cut -c 45-49`
        expr $homedf \> 80 > /dev/null
        if [ $? = 0 ]
        then
                home_err="警告: home disk 使用率过高,达到$homedf% !!!\c"
                date >> moni.log
                echo "警告: home disk 使用率过高,达到$homedf% !!!" >> moni.log
        fi
        echo    "home disk 占用率     $homedf%\c"               

        echo $home_err         
        echo '------------------------------------------------------------------
-------'
        uptime
        sleep 300
done               

可以根据自己的需要再添加一些.当然也可以改进不少,这是偶以前写的.

论坛徽章:
0
4 [报告]
发表于 2003-07-08 09:53 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

还不如直接用sun management center好了,呵呵

论坛徽章:
0
5 [报告]
发表于 2003-07-09 10:32 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

饮鸩止渴,有钱的话我也会考虑买一套这样的软件,可现在是实际解决问题的时候,来点实的。
谢谢红袖添香和nkliyong,我是新手,以后还请多指教。

论坛徽章:
0
6 [报告]
发表于 2003-07-10 21:39 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

Does solaris have a cmd named "top" ?

论坛徽章:
0
7 [报告]
发表于 2003-07-11 08:24 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

以前在网上找到的一个现成的脚步。但是我对netstat 的用法一直没有看懂,如果明白请告知。

===========

#!/bin/sh
# sccsid: @(#)watch.system      1.18   08/23/99 13:20:10
#
# watch.system: Watches the system.  Alternative to the "watcher" program.
# Add a line to cron like the below to run it, perferably not as root:
#
## watch the system, to see if it's been good or bad
##
# 15,45 * * * * /etc/watch.system
##
# See comments regarding Solaris 2 throughout the file
#
# User settables
#
FT="-t 4.2"                     # File system type, should be 4.2
FZ=98                           # Maxium percent file system used
IN=70                           # Maxium percent inodes used per file system
NET=le0                         # Network interface
PSLIMIT=99                      # Maxium number of processes to be running
RATE=100                        # Collision rate, lower means more tolerant
WARNSWAP=15000          # Remaining swap space warning level
DANGERSWAP=8000         # Remaining swap space danger level
MEMWARNING=15           # Real Memory warning level
LOADWARNING=10          # Load average warning level
LOADDANGER=15           # Load average danger level
MAILTO=root             # Who to tell
EXCLUDES='Filesystem'  # df Don't check these, egrep fs1|fs2|etc syntax
#
# End of normal user settables

HOST=`hostname`
PATH=/usr/ucb:/bin:/usr/bin:/usr/etc:/usr/local/bin:/etc; export PATH

#
# Collison rate routine, $9 + 1 is a hack to avoid devision by zero
# in the awk statement.  The -gt 0 check is a catch for the roll over
# to negative numbers on packet counters.
#
NS=`netstat -i | grep $NET`

COLL=`echo $NS | awk '{ N = ( $9 + 1 ); C = ( $5 + $7 ) / N } { print C }'`

if [ $COLL -gt 0 -a $RATE -gt $COLL ]; then
        SUB="WARNING $HOST collision rate 1 in $COLL"
        netstat -i | /usr/ucb/mail -s "$SUB" $MAILTO
fi
#
#
# File system size
#
DF=`df $FT | egrep -v $EXCLUDES | awk '{print $5}' | sed 's/%//g'`

for I in $DF;do

if [ $I -gt $FZ ]; then
        SUB="WARNING $HOST file system over $FZ percent full"
        df $FT | egrep -v $EXCLUDES | /usr/ucb/mail -s "$SUB" $MAILTO
        break
fi

done

#
# Inode usage
#
# Uncomment first df line for SunOS, second line for Solaris
#
#DFI=`df $FT -i | grep % | awk '{print $4}' | sed 's/%//g'`

DFI=`df -i | grep % | awk '{print $4}' | sed 's/%//g'`

for I in $DFI; do

if [ $I -gt $IN ]; then
        SUB="WARNING `hostname` inode usage over $IN percent"
        df -i $FT | /usr/ucb/mail -s "$SUB" $MAILTO
        break
fi

done

#
# Load averages.  Generally 10 is bad, 20 is really bad.  Use top if you
# have it, otherwise use uptime.
#

UP=`uptime | awk -Fg '{print $2}' | awk -F: '{print $2}' | awk -F, '{print $1}'`

if [ $UP -ge $LOADDANGER ]; then
        SUB="DANGER `hostname` load average at $UP"
#       uptime | /usr/ucb/mail -s "$SUB" $MAILTO
        top -d1 -n1| /usr/ucb/mail -s "$SUB" $MAILTO

elif [ $UP -ge $LOADWARNING ]; then
        SUB="WARNING `hostname` load average at $UP"
#       uptime | /usr/ucb/mail -s "$SUB" $MAILTO
        top -d1 -n1| /usr/ucb/mail -s "$SUB" $MAILTO
fi

#
# Real memory usage.
#
MEM=`top -d1 -n1| grep Memory | sed 's/M/ /g'| awk '{ print $4 }'`

if      [ $MEM -le $MEMWARNING ]; then
        SUB="WARNING `hostname` real memory free down to $MEM"
        top -ores -d1 | /usr/ucb/mail -s "$SUB" $MAILTO
fi

#
# Mbufs in use, comment this section out for use with Solaris 2
#

#MB=`netstat -m | grep "mbufs in use" | sed 's:/: :g'|awk '{ print $2 }'`
#
#if [ $MB -gt 3000 ]; then
#    SUB="DANGER `hostname` $MB mbufs allcated"
#    echo "`netstat -m`" | /usr/ucb/mail -s "$SUB" $MAILTO
#
#elif [ $MB -gt 2000 ]; then
#    SUB="WARNING `hostname` $MB mbufs allcated"
#    echo "`netstat -m`" | /usr/ucb/mail -s "$SUB" $MAILTO
#fi


#
# Number of processes running
#
PS=`ps ax | wc -l`

if [ $PS -gt $PSLIMIT ]; then
        SUB="WARNING `hostname` $PS running processes"
        ps ax | /usr/ucb/mail -s "$SUB" $MAILTO
fi

#
# check free swap space
#
# uncomment the pstat line for SunOS or the /etc/swap line for Solaris 2
#
#SWAP=`pstat -T | grep swap | awk -F/ '{print $1 " " $2}' | awk '{ C = $2 - $1} { print C }'`

SWAP=`/etc/swap -s | awk -F, '{print $2}' | awk -Fk '{print $1}'`

if [ $SWAP -lt $DANGERSWAP ]; then
        SUB="DANGER $HOST only $SWAP bytes of swap space left"
        swap -s | /usr/ucb/mail -s "$SUB" $MAILTO

elif [ $SWAP -lt $WARNSWAP ]; then
        SUB="WARNING $HOST only $SWAP bytes of swap space left"
        swap -s  | /usr/ucb/mail -s "$SUB" $MAILTO
fi
==========

论坛徽章:
0
8 [报告]
发表于 2003-07-11 09:16 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

原帖由 "yiyu_66" 发表:
饮鸩止渴,有钱的话我也会考虑买一套这样的软件,可现在是实际解决问题的时候,来点实的。
谢谢红袖添香和nkliyong,我是新手,以后还请多指教。
   
任意一套solaris 系统都带smc的啊
呵呵,而且大部分功能都是免费的,其中就有性能监控,磁盘监控,文件扫描,目录大小监控等等等等

论坛徽章:
0
9 [报告]
发表于 2003-07-11 10:43 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

SMC对内存要求太高,而且功能有限的很,对了,4800上如何做文件扫描和目录大小监控?

论坛徽章:
0
10 [报告]
发表于 2003-07-11 11:52 |只看该作者

[求助]如何用shell编写系统性能的监控的脚本!!!

文件扫描模块是已经添加的,默认扫描messages文件
可以添加文件扫描模块的实例
目录大小监控模块需要手动加载
然后在里面添加行就可以了     

所有的系统都是一样的啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP