如下腳本寫於redmine性能排查時,用於定位系統性能瓶頸的採樣,源地址爲~/performanceLog/collectLog.sh中,計劃放入github的代碼片斷庫中.html
注: 若是mysql的地址或者目錄更換,此腳本中dstat 的mysql相關數據的採集須要重寫其插件的mysql鏈接部分的代碼。 注: 若是mysql的地址或者目錄有更換,又想使用如下腳本採集數據,須要重寫其mysql鏈接部分的代碼,才能讓腳本中dstat 的mysql相關數據的採集正常獲取。mysql
#!/bin/bash cd /home/pset/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="_nohup.log" 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 ruby.bin pidMysqld=`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 $@ -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.sh crontab設置成每小時啓動,並依照腳本中設定的頻率採集數據: 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的指標信息ios
相關頁面: http://www.cnblogs.com/ToDoToTry/p/4462609.html git