访问次数
我的另一个总结性博客: todototry 大米粒

linux 系统性能指标采样脚本

 

以下脚本写于redmine性能排查时,用于定位系统性能瓶颈的采样,源地址为~/performanceLog/collectLog.sh中,计划放入github的代码片段库中.


注: 如果mysql的地址或者目录更换,此脚本中dstat 的mysql相关数据的采集需要重写其插件的mysql连接部分的代码。 注: 如果mysql的地址或者目录有更换,又想使用以下脚本采集数据,需要重写其mysql连接部分的代码,才能让脚本中dstat 的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的指标信息

 

 

相关页面: http://www.cnblogs.com/ToDoToTry/p/4462609.html 

posted @ 2015-05-05 12:43  fandyst  阅读(2038)  评论(0编辑  收藏  举报