2023年12月9日發(fā)(作者:古代成語故事)

linux系統(tǒng)性能指標采樣腳本
以下腳本寫于redmine性能排查時,用于定位系統(tǒng)性能瓶頸的采樣,源地址為~/performanceLog/中,計劃放入github的代碼片段庫中.
注: 如果mysql的地址或者目錄更換,此腳本中dstat 的mysql相關(guān)數(shù)據(jù)的采集需要重寫其插件的mysql連接部分的代碼。 注: 如果mysql的地址或者目錄有更
換,又想使用以下腳本采集數(shù)據(jù),需要重寫其mysql連接部分的代碼,才能讓腳本中dstat 的mysql相關(guān)數(shù)據(jù)的采集正常獲取。
#!/bin/bash
cd /home/pt/performanceLog/
#create dir for today
today=`date "+%Y%m%d"`
if [ ! -d $today ]; then
mkdir $today;
fi
cd $today
#declare var to remember current hour.
hour=`date "+%H"`
echo "current hour is: "$hour
postfix="_"
filenameOfDstat=$hour"_"$today"_dstat"$postfix".csv"
echo $filenameOfDstat
filenameOfIostat=$hour"_"$today"_iostat"$postfix
echo $filenameOfIostat
filenameOfPidstat=$hour"_"$today"_pidstat"$postfix
echo $filenameOfPidstat
filenameOfFree=$hour"_"$today"_free"$postfix
echo $filenameOfFree
filenameOfMemInfo=$hour"_"$today"_meminfo"$postfix
echo $filenameOfMemInfo
filenameOfUptime=$hour"_"$today"_Uptime"$postfix
echo $filenameOfUptime
filenameOfMpstat=$hour"_"$today"_mpstat"$postfix
echo $filenameOfMpstat
filenameOfIOtop=$hour"_"$today"_iotop"$postfix
echo $filenameOfIOtop
filenameOfSar=$hour"_"$today"_sar"$postfix
echo $filenameOfSar
#the process id which we are intrested in.: mysqld
pidMysqld=`ps -e| grep |awk 'NR==1 {print $1}'`
pidRuby=`ps -e| grep |awk 'NR==1 {print $1}'`
export DSTAT_MYSQL_USER='root'
export DSTAT_MYSQL_PWD='1111'
nohup dstat -t --mysql5-cmds --mysql5-io --mysql5-keys $@ -df --disk-util --disk --mem --proc --top-cpu --top-latency --top-bio --io --sys --filesystem --tcp --vm --output $filenameOfDstat 1 3600 &
nohup pidstat -p $pidMysqld -u -d -w -h 2 1800 > $filenameOfPidstat &
nohup mpstat -P ALL 2 1800 > $filenameOfMpstat &
nohup iotop -p $pidMysqld -n 1800 -d 2 > $filenameOfIOtop &
nohup iostat -dxk 2 1800 > $filenameOfIostat &
#nohup sar -o $filenameOfSar 2 1800 &
#nohup free > $filenameOfFree &
#nohup cat /proc/meminfo > $filenameOfMemInfo &
#nohup uptime > $filenameOfUptime &
# in every day at april ,run the shell script at 1 min past each hour.
#1 * * 4 * /root/shift_my_
#1 * * 4 * /home/pt/performanceLog/
crontab設置成每小時啟動,并依照腳本中設定的頻率采集數(shù)據(jù):
1 0,4,10-23 * 4 * /home/pt/performanceLog/
* * * 4 * /usr/local/bin/mycheckpoint --ur=root --password=1111 --socket=/redmine/mysql/tmp/ --databa=mycheckpoint
產(chǎn)生此方案的關(guān)鍵系統(tǒng)指標展示:
pidstat:可以針對特定的進程,比如:mysql 或者其它進程
mpstat:用于查看高峰時段某些cpu的idle是否異常。dstat io:用于記錄每次采集的時間點,并統(tǒng)籌全局的cpu mem io net mysql的指標信息
本文發(fā)布于:2023-12-09 21:31:22,感謝您對本站的認可!
本文鏈接:http://www.newhan.cn/zhishi/a/1702128683241137.html
版權(quán)聲明:本站內(nèi)容均來自互聯(lián)網(wǎng),僅供演示用,請勿用于商業(yè)和其他非法用途。如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除。
本文word下載地址:linux系統(tǒng)性能指標采樣腳本.doc
本文 PDF 下載地址:linux系統(tǒng)性能指標采樣腳本.pdf
| 留言與評論(共有 0 條評論) |