设为首页 加入收藏

TOP

mysql计算指定时间内TPS(一)
2015-11-21 02:01:32 来源: 作者: 【 】 浏览:2
Tags:mysql 计算 指定 时间 TPS
 
 
有朋友留言,需要监控指定时间内如早上9定到18点的TPS,写了一个10秒内TPS的方法.  
  
#!/bin/bash  
export 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-echo.  
    # 参数 $1 = message  
    # 参数 $2 = color  
{  
local default_msg="No message passed."  
  
message=${1:-$default_msg}  # 如果$1没有输入则为默认值default_msg.  
color=${2:-black}       # 如果$1没有输入则为默认值black.  
  
case $color in  
    black)  
         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即恢复默认值  
  printf "$black"  
  
return  
}  
  
  
cechon ()         
  
    # Color-echo.  
    # 参数1 $1 = message  
    # 参数2 $2 = color  
{  
local default_msg="No message passed."  
                # Doesn't really need to be a local variable.  
  
message=${1:-$default_msg}  # 如果$1没有输入则为默认值default_msg.  
color=${2:-black}       # 如果$1没有输入则为默认值black.  
  
case $color in  
    black)  
        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即恢复默认值  
  printf "$black"  
  
return  
}  
  
  
#set mysql evn  
MYSQL_USER=root  #mysql的用户名  
MYSQL_PASS='123'  #mysql的登录用户密码  
MYSQL_HOST=localhost  
  
#TPS01(间隔时间内事务量)  
####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=10  
tps_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 >${tps_re02}  
mysql -h${MYSQL_HOST} -u${MY
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇mysql中文乱码解决方案 下一篇mysql 5.5 升级到 mysql 5.6

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: