最近碰到一个实时查看MYSQL的TPS的需求,查找了下资料
TPS = (Com_commit + Com_rollback) / 数据库的uptime
use information_schema;
select variable_value into @num_com from global_status where variable_name ='COM_COMMIT';
select variable_value into @num_roll from global_status where variable_name ='COM_ROLLBACK';
select variable_value into @uptime from global_status where variable_name ='uptime';
select (@num_com+@num_roll)/@uptime;
由于MYSQL -E选项中不支持参数
写成脚本只好用直接结果赋值
com_ro=`mysql -e "show status like 'com_rollback'"`
com_co=`mysql -e "show status like 'com_commit'"`
uptime=`mysql -e "show status like 'uptime'"`
TPS=($com_ro+$com_co)/$uptime