MySQL calculates TPS within a specified time

Source: Internet
Author: User

<pre name= "code" class= "SQL" > Have a friend message, you need to monitor the TPS for a specified time, such as 9 to 18 in the morning, and write a method of TPS within 10 seconds. #!/bin/bashexport black= ' \033[ 0m ' export boldblack= ' \033[1;0m ' export red= ' \033[31m ' export boldred= ' \033[1;31m ' export green= ' \033[32m ' export boldgreen= ' \033[1;32m ' export yellow= ' \033[33m ' export boldyellow= ' \033[1;33m ' export blue= ' \033[34m ' export boldblue= ' \033[1;34m ' export magenta= ' \033[35m ' export boldmagenta= ' \033[1;35m ' export cyan= ' \033[36m ' export boldcyan= ' \033[1; 36m ' export white= ' \033[37m ' export boldwhite= ' \033[1;37m ' Cecho () # #--Function to easliy print colored text--# # # COLOR-E cho.# parameter $ = message# parameter $ = color{local default_msg= "No message passed." message=${1:-$default _msg}# If no input is the default value default_msg.color=${2:-black}# if no input is the default black.case $color inblack) printf "$black";; Boldblack) printf "$boldblack";; Red) printf "$red";; boldred) printf "$boldred";; Green) printf "$green";; Boldgreen) printf "$boldgreen";; Yellow) printf "$yellow";; Boldyellow) printf "$boldyellow";; Blue) printf "$blue";; BOldblue) printf "$boldblue";; Magenta) printf "$magenta";; Boldmagenta) printf "$boldmagenta";; Cyan) printf "$cyan";; Boldcyan) printf "$boldcyan";; White) printf "$white";; Boldwhite) printf "$boldwhite";; Esac printf "%s\n" "$message" tput sgr0# tput sgr0 Restore default printf "$black" Return}cechon () # color-echo.# parameter 1 $ = Messag e# Parameter 2 $ = color{local default_msg= "No message passed." # doesn ' t really need to be a local variable.message=${1:-$default _msg}# if $ $ is not entered then the default value default_msg.color=${2:-black}# if $ 1 No input is the default value black.case $color inblack) printf "$black";; Boldblack) printf "$boldblack";; Red) printf "$red";; boldred) printf "$boldred";; Green) printf "$green";; Boldgreen) printf "$boldgreen";; Yellow) printf "$yellow";; Boldyellow) printf "$boldyellow";; Blue) printf "$blue";; Boldblue) printf "$boldblue";; Magenta) printf "$magenta";; Boldmagenta) printf "$boldmagenta";; Cyan) printf "$cyan";; Boldcyan) printf "$boldcyan";; White) printf "$white";; Boldwhite) printf "$boldwhite";; Esac printf "%s" "$message "Tput sgr0# tput sgr0 Restore default printf" $black "return} #set mysql evnmysql_user=root #mysql的用户名MYSQL_PASS = ' 123 ' #m Ysql Login User Password mysql_host=localhost#tps01 (amount of transactions over time) # # #TPS = (com_commit + com_rollback)/seconds ####### #mysql > show Global status like ' Com_insert '; ####### #mysql > Show global status Like ' Com_update '; ####### #mysql > Show global status Like ' Com_delete '; # # # #sleep_time =10tps_01= "show global Status where Variable_name in (' Com_insert '); "Tps_02=" show global Status where Variable_name in (' com_update '); "Tps_03=" show global Status where Variable_name in (' Com_delete '); "Tps_re01=" tpsre01. ' Date +%y%m%d%h%m%s '. txt ' tps_re02= ' tpsre02. ' Date +%y%m%d%h%m%s '. txt ' tps_re03= ' tpsre03. ' Date +% y%m%d%h%m%s '. txt ' mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${tps_01}" |grep-v variable_name |cut-f 2 ; ${tps_re01}mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${tps_02}" |grep-v variable_name |cut-f 2 &GT;${TP S_re02}mysql-h${mysql_host}-u${mysql_uSER}-p${mysql_pass}-E "${tps_03}" |grep-v variable_name |cut-f 2 >${tps_re03}tps_01_re= ' cat ${tps_re01} ' tps_02_re= ' Cat ${tps_re02} ' tps_03_re= ' Cat ${tps_re03} ' tps_sum_now= ' awk ' begin{print ' ${tps_01_re} ' + ' ${tps_02_re} ' + ' ${tps_03_ Re} '} ' #shell默认不支持浮点运算rm-rf ${tps_re01}rm-rf ${tps_re02}rm-rf ${tps_re03}echo "acquiring TPS value:" Sleep ${sleep_time}tps_021 = "Show global status where Variable_name in (' Com_insert '); "Tps_022=" show global Status where Variable_name in (' com_update '); "Tps_023=" show global Status where Variable_name in (' Com_delete '); "Tps_re021=" tpsre021. ' Date +%y%m%d%h%m%s '. txt ' tps_re022= ' tpsre022. ' Date +%y%m%d%h%m%s '. txt ' tps_re023= ' tpsre023. ' Date +%y%m%d%h%m%s '. txt ' mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${tps_021}" |grep-v Variable_name |  Cut-f 2 >${tps_re021}mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${tps_022}" |grep-v Variable_name |cut -F 2 >${tps_re022}mysql-h${mysql_host}-u${mysql_user}-p${mysql_pass}-E "${tps_023}" |grep -V variable_name |cut-f 2 >${tps_re023}tps_021_re= ' cat ${tps_re021} ' tps_022_re= ' Cat ${tps_re022} ' tps_023_re= ' cat $ {tps_re023} ' tps_sum_new= ' awk ' begin{print ' ${tps_021_re} ' + ' ${tps_022_re} ' + ' ${tps_023_re} '} ' tps_sum_diff= ' awk ' Begin{print ' ${tps_sum_new} '-' ${tps_sum_now} ' ' tps_avg= ' awk ' begin{print ' ${tps_sum_diff} '/' ${sleep_time} '} ' #                                                                           The shell does not support floating-point arithmetic by default Cechon "within the last $sleep _time Seconds,tps is: ${tps_avg}" Redecho "                                                                           "Echo"      "Rm-rf ${tps_re021}rm-rf ${tps_re022}rm-rf ${tps_re023}########### #运行结果正在获取TPS值: Within the last Seconds,tps is:0.9


MySQL calculates TPS within a specified time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.