计算qps和tps脚本
#!/bin/bash
#********************************************************************
# File Name: xxx.sh
# Version: V1.0
# Author: dahuangji
# Email:
# Created Time : 2022-02-13 02:14:04
# Description:
#********************************************************************
RED='\E[31;2m'
GREEN='\E[32;1m'
END='\E[0m'
#第一种计算qps,笼统计算
mysql_qps() {
TIME=$1
old_query=`mysql -e 'show global status like "questions"'|awk 'NR==2{print $2}'`
sleep $TIME
new_query=`mysql -e 'show global status like "questions"'|awk 'NR==2{print $2}'`
querys=$((new_query-old_query))
resule_int=$(echo "scale=2; $querys/$TIME"|bc)
resule_dub=$(echo "scale=2; $querys/$TIME"|bc|grep '^\.')
if $resule_dub 2> /dev/null ;then
echo -e "$GREEN $TIME秒的QPS为:$resule_int $END"
else
echo -e "$GREEN $TIME秒的QPS为:0$resule_dub $END"
fi
}
#第二种计算qps,精确计算
mysql_qps2() {
TIME=$1
old_query=$(echo `mysql -e "show global status where variable_name in('com_select','com_insert','com_delete','com_update')"\
|awk 'NR!=1{print $2}'`\
|tr -t " " "+"|bc)
sleep $TIME
new_query=$(echo `mysql -e "show global status where variable_name in('com_select','co
m_insert','com_delete','com_update')"\
|awk 'NR!=1{print $2}'`\
|tr -t " " "+"|bc)
querys=$((new_query-old_query))
resule_int=$(echo "scale=2; $querys/$TIME"|bc)
resule_dub=$(echo "scale=2; $querys/$TIME"|bc|grep '^\.')
if $resule_dub 2> /dev/null ;then
echo -e "$GREEN $TIME秒的QPS为:$resule_int $END"
else
echo -e "$GREEN $TIME秒的QPS为:0$resule_dub $END"
fi
}
#第一种计算tps方式,笼统计算
mysql_tps() {
TIME=$1
old_tran=$(echo `mysql -e "show global status where variable_name in('com_commit','com_rollback')"\
|awk 'NR!=1{print $2}'`\
|tr -t ' ' '+'|bc)
sleep $TIME
new_tran=$(echo `mysql -e "show global status where variable_name in('com_commit','com_rollback')"\
|awk 'NR!=1{print $2}'`\
|tr -t ' ' '+'|bc)
trans=$((old_trans-new_trans))
resule_int=$(echo "scale=2; $trans/$TIME"|bc)
resule_dub=$(echo "scale=2; $trans/$TIME"|bc|grep '^\.')
if $resule_dub 2> /dev/null ;then
echo -e "$GREEN $TIME秒TPS为:$resule_int $END"
else
echo -e "$GREEN $TIME秒TPS为:$resule_dub $END"
fi
}
#第二种计算tps方式,精确计算
mysql_tps2() {
TIME=$1
old_tran=$(echo `mysql -e "show global status where variable_name in('com_insert','com_delete','com_update')"\
|awk 'NR!=1{print $2}'`\
|tr -t ' ' '+'|bc)
sleep $TIME
new_tran=$(echo `mysql -e "show global status where variable_name in('com_insert','com_delete','com_update')"\
|awk 'NR!=1{print $2}'`\
|tr -t ' ' '+'|bc)
trans=$((old_trans-new_trans))
resule_int=$(echo "scale=2; $trans/$TIME"|bc)
resule_dub=$(echo "scale=2; $trans/$TIME"|bc|grep '^\.')
if $resule_dub 2> /dev/null ;then
echo -e "$GREEN $TIME秒TPS为:$resule_int $END"
else
echo -e "$GREEN $TIME秒TPS为:$resule_dub $END"
fi
}
. xxx.sh
mysql_qps 3
mysql_qps2 3
