Solaris环境下性能采集脚本C

本文介绍了一个用于监控系统资源的Shell脚本,包括CPU使用率、内存占用情况及磁盘I/O等关键指标的收集方法。该脚本通过iostat、vmstat等工具获取数据,并将结果保存到指定文件中,便于后续分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#--------------------------------------
#Show simple usage information
#--------------------------------------
usage()
{
echo "Usage: sh ./collectMan.sh [-process] processName [-cpu] [-memory] [-diskio] diskName [-net] netif [-summary]"
echo "Example: sh ./collectMan.sh -q -period 10 -process dataserver IPMSDm DCServer EnpowerDm -cpu -memory -diskio c1t0d0s0 c1t1d0s6 c1t2d0s6 -net -summary"
echo "!!! For simply use, just input 'sh ./collectMan.sh'. This will collect data for all CMF CBB. !!!"
}

#--------------------------------------
#Print an error and exit
#--------------------------------------
error()
{
echo "$1"
exit 1
}

#--------------------------------------
#Print debug information
#--------------------------------------
debug()
{
if [ $COLLECT_DEBUG = "Y" ]
then
echo "$1"
fi
}


#--------------------------------------
#get cpu id from command line and save it to cpuid.cfg
#--------------------------------------
get_cpuid()
{
#Use iostat to get cpu usage for whole system
echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_iostat_cpu.txt
nohup iostat -c $COLLECT_PERIOD >> ./report/temp_iostat_cpu.txt &

#Use mpstat to get cpu usage for each cpu
echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_mpstat.txt
nohup mpstat $COLLECT_PERIOD >> ./report/temp_mpstat.txt &

if [ -f ./cpuid.cfg ]
then
rm ./cpuid.cfg
fi

while [ -n "$1" ]; do
case $1 in
-*) break;; # no more cpuid input
*) echo $1 >> ./cpuid.cfg; shift 1;;
esac
done
}

#--------------------------------------
#Collect memory information
#--------------------------------------
get_memory()
{
echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_vmstat.txt
nohup vmstat $COLLECT_PERIOD >> ./report/temp_vmstat.txt &
}

#--------------------------------------
#get disk id from command line and save it to disk.cfg
#--------------------------------------
get_disk()
{
#use iostat get disk io information
echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_iostat.txt
nohup iostat -xpn $COLLECT_PERIOD >> ./report/temp_iostat.txt &

if [ -f ./disk.cfg ]
then
rm ./disk.cfg
fi

while [ -n "$1" ]; do
case $1 in
-*) break;; # no more disk input
*) echo $1 >> ./disk.cfg; shift 1;;
esac
done

#If not input parameter, get all disk partition in df -k list (but summary report just use first three partition)
if [ ! -f ./disk.cfg ]
then
df -k |grep dsk |awk '{print $1}' > ./temp_disk.cfg
while read LINE
do
basename $LINE >> ./disk.cfg

done < ./temp_disk.cfg
rm ./temp_disk.cfg
fi

return 0
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值