標籤:
以下指令碼寫於redmine效能排查時,用於定位系統效能瓶頸的採樣,源地址為~/performanceLog/collectLog.sh中,計劃放入github的程式碼片段庫中.
註: 如果mysql的地址或者目錄更換,此指令碼中dstat 的mysql相關資料的採集需要重寫其外掛程式的mysql串連部分的代碼。 註: 如果mysql的地址或者目錄有更換,又想使用以下指令碼採集資料,需要重寫其mysql串連部分的代碼,才能讓指令碼中dstat 的mysql相關資料的採集正常擷取。
#!/bin/bashcd /home/pset/performanceLog/#create dir for todaytoday=`date "+%Y%m%d"`if [ ! -d $today ]; thenmkdir $today; ficd $today#declare var to remember current hour.hour=`date "+%H"`echo "current hour is: "$hourpostfix="_nohup.log"filenameOfDstat=$hour"_"$today"_dstat"$postfix".csv"echo $filenameOfDstatfilenameOfIostat=$hour"_"$today"_iostat"$postfixecho $filenameOfIostatfilenameOfPidstat=$hour"_"$today"_pidstat"$postfixecho $filenameOfPidstatfilenameOfFree=$hour"_"$today"_free"$postfixecho $filenameOfFreefilenameOfMemInfo=$hour"_"$today"_meminfo"$postfixecho $filenameOfMemInfofilenameOfUptime=$hour"_"$today"_Uptime"$postfixecho $filenameOfUptimefilenameOfMpstat=$hour"_"$today"_mpstat"$postfixecho $filenameOfMpstatfilenameOfIOtop=$hour"_"$today"_iotop"$postfixecho $filenameOfIOtopfilenameOfSar=$hour"_"$today"_sar"$postfixecho $filenameOfSar#the process id which we are intrested in.: mysqld ruby.binpidMysqld=`ps -e| grep mysqld.bin|awk ‘NR==1 {print $1}‘`pidRuby=`ps -e| grep ruby.bin|awk ‘NR==1 {print $1}‘`export DSTAT_MYSQL_USER=‘root‘export DSTAT_MYSQL_PWD=‘1111‘nohup dstat -t --mysql5-cmds --mysql5-io --mysql5-keys [email protected] -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_times.sh#1 * * 4 * /home/pset/performanceLog/collectLog.shcrontab設定成每小時啟動,並依照指令碼中設定的頻率採集資料:1 0,4,10-23 * 4 * /home/pset/performanceLog/collectLogs.sh* * * 4 * /usr/local/bin/mycheckpoint --user=root --password=1111 --socket=/redmine/mysql/tmp/mysql.sock --database=mycheckpoint
產生此方案的關鍵系統指標展示:
pidstat:可以針對特定的進程,比如:mysql 或者其它進程
mpstat:用於查看高峰時段某些cpu的idle是否異常。
dstat io:用於記錄每次採集的時間點,並統籌全域的cpu mem io net mysql的指標資訊
相關頁面: http://www.cnblogs.com/ToDoToTry/p/4462609.html
linux 系統效能指標採樣指令碼