#!/bin/sh
INTERVAL=5
PASSWORD='-ucncn -p123456'
PREFIX=$INTERVAL-sec-status
RUNFILE=/www/logs/mysql_bench
mysql -e 'SHOW GLOBAL VARIABLES' $PASSWORD >> mysql-variables
while test -e $RUNFILE; do
file=$(date +%F_%I)
sleep=$(date +%s.%N | awk "{print $INTERVAL - (/$1 % $INTERVAL)}")
sleep $sleep
ts="$(date + "TS %s.%N %F %T")"
loadavg="$(uptime)"
echo "$ts $loadavg" >> $PREFIX-${file}-status
mysql -e 'SHOW GLOBAL STATUS' $PASSWORD >> $PREFIX-${file}-status &
echo "$ts $loadavg" >> $PREFIX-${file}-innodbstatus
echo -e 'SHOW ENGINE INNODB STATUS/G' $PASSWORD >> $PREFIX-${file}-innodbstatus &
echo "$ts $loadavg" >> $PREFIX-${file}-processlist
mysql -e 'SHOW FULL PROCESSLIST/G' $PASSWORD >> $PREFIX-${file}-processlist & echo $ts
done
echo Exiting because $RUNFILE does not exist.
这个shell脚本很简单,但提供了一个有效的收集状态和性能数据的框架。
新闻热点
疑难解答