msyql TPS v1:计算指定时间内

需求:计算每天业务高峰期9:00-18:00的TPS.

思路:1.每天早上9点定时记录下TPS相关的历史值  2.任意当前时间获取TPS相关的值减去早上9点记录的值 3.获取早上9点到当前时间的秒数

/***********************

1.定时job

**********************

#!/bin/bash

#[email protected]

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

#每天9点生成TPS历史值和时间值

last_exec_time="/root/tps_lastime.`date +%Y%m%d`.txt"

t01=`date "+%Y-%m-%d %H:%M:%S" >${last_exec_time}`

tps_everydat_9="tps_everydat_9.`date +%Y%m%d`.txt"

#TPS(每秒事务量)

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${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_everydat_9="/root/tps_everydat_9.`date +%Y%m%d`.txt"

tps_sum_now=`awk ‘BEGIN{print ‘${tps_01_re}‘ + ‘${tps_02_re}‘ + ‘${tps_03_re}‘}‘ >${tps_everydat_9}` #shell默认不支持浮点运算

rm -rf ${tps_re01}

rm -rf ${tps_re02}

rm -rf ${tps_re03}

/***********************

2.脚本

**********************

#!/bin/bash

#[email protected]

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

tps_051="show  global status where Variable_name in(‘Com_insert‘); "

tps_052="show  global status where Variable_name in(‘Com_update‘); "

tps_053="show  global status where Variable_name in(‘Com_delete‘); "

tps_re051="tpsre051.`date +%Y%m%d%H%M%S`.txt"

tps_re052="tpsre052.`date +%Y%m%d%H%M%S`.txt"

tps_re053="tpsre053.`date +%Y%m%d%H%M%S`.txt"

mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${tps_051}" |grep -v Variable_name \

|cut -f 2 >${tps_re051}

mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${tps_052}" |grep -v Variable_name \

|cut -f 2 >${tps_re052}

mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -e"${tps_053}" |grep -v Variable_name \

|cut -f 2 >${tps_re053}

tps_051_re=`cat ${tps_re051}`

tps_052_re=`cat ${tps_re052}`

tps_053_re=`cat ${tps_re053}`

tps_sum_new=`awk ‘BEGIN{print ‘${tps_051_re}‘ + ‘${tps_052_re}‘ + ‘${tps_053_re}‘ }‘`

#获取上一次的值(见TPS-JOB)

tps_everydat_9="/root/tps_everydat_9.`date +%Y%m%d`.txt"

tps_sum_old=`cat ${tps_everydat_9}`

tps_sum_diff=`awk ‘BEGIN{print ‘${tps_sum_new}‘ - ‘${tps_sum_old}‘ }‘ `

#获取时间差

last_exec_time="/root/tps_lastime.`date +%Y%m%d`.txt"

t02=`cat ${last_exec_time}`

start_time=`date +%s -d "$t02"`

end_time=`date +%s `

#echo $(($end_time-$start_time))

tps_uptime_gf=`awk ‘BEGIN{ print ‘$end_time‘-‘$start_time‘}‘`

#计算早上9点到现在的TPS

tps_avg=`awk ‘BEGIN{print ‘${tps_sum_diff}‘ / ‘${tps_uptime_gf}‘}‘|awk ‘{printf("%.f\n",$1)}‘` #shell默认不支持浮点运算

cechon "From $t02 to now ,TPS: ${tps_avg} " red

echo "                                                                           "

tps_01_re=`cat ${tps_re051}`

tps_02_re=`cat ${tps_re052}`

tps_03_re=`cat ${tps_re053}`

echo

rm -rf ${tps_re051}

rm -rf ${tps_re052}

rm -rf ${tps_re053}

时间: 2024-08-29 20:54:54

msyql TPS v1:计算指定时间内的相关文章

mysql计算指定时间内TPS

<pre name="code" class="sql">有朋友留言,需要监控指定时间内如早上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=

js学习总结----动画之在指定时间内实现单方向匀速运动

具体代码如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ margin:0; padding:0; } #box{ position:absolute; top:0; left:0; padding:0; width:100px; h

计算指定日期的前N个月日期

/**     * 计算指定日期的前N个月日期     * @param type $time      * @param int $month_length     * @return date     */    public function calLMP($time,$month_length ){        $r = date('Y-m-d',strtotime('-'.$month_length.'month',strtotime($time)));        list($e

计算指定字符串出现次数插件

计算指定字符串出现次数插件: 有时候需要计算移一段字符串中指定字符串的出现次数,可能应用不是那么频繁. 本章节分享一段代码实例能够实现类似的功能,当然也可以根据实际需要进行扩展. 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.51texiao.cn/&q

先排序,再限定记录数,然后计算指定字段的总和

mongo XXXX:27017 mongo 127.0.0.1:27017(localhost)show databasesuse xx(数据库)dbshow collections 无结果//db.proccessedfile.aggregate([{$match:{dataNumber:{$gte:1,$lte:9}}},{$group:{_id:null,sum:{$sum:"$dataNumber"}}}])无结果//db.proccessedfile.aggregate([

查询指定时间内审核失败的事件日志

查询指定时间内审核失败的事件日志,必须要加namespace,否则无返回 $s = get-date "3/30/2016 13:54:03" $e = get-date "3/30/2016 13:55:03" $stime = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime($s) $etime = [System.Management.ManagementDateTimeConve

iOS规范化时间格式,object-C计算指定时间与当前的时间差

object-c计算指定时间与当前的时间差 头文件(.h): #import <Foundation/Foundation.h> @interface LuDate : NSDate +(NSString *) compareCurrentTime:(NSString*) strDate; @end .m文件: /** * 计算指定时间与当前的时间差 * @param compareDate 某一指定时间 * @return 多少(秒or分or天or月or年)+前 (比如,3天前.10分钟前)

JavaScript 计算指定月份有多少天

用 js 画工作日历的时候,需要用 js 计算指定月份一共有多少天 在网上找了些方法,都比较繁琐,后来灵机一动,想到一个偷懒的办法,分享一下 一.原理分析 要想得到某月有多少天,只需要获取到当月最后一天的日期就行了 围绕这一思路,灵活调用 setMonth(),getMonth(),setDate(),getDate(),计算出所需日期 二.代码实现 function getMonthLength(date) { let d = new Date(date) // 将日期设置为下月一号 d.se

10.1 优化函数 在前面的章节中,我们已经知道,递归是 F# 中处理函数的主要控制流机制。我们第一次是使用它写一些进行计算的简单函数,例如,计算指定范围内的数字的和或阶乘。后来,我们发现它在处理递

10.1 优化函数 在前面的章节中,我们已经知道,递归是 F# 中处理函数的主要控制流机制.我们第一次是使用它写一些进行计算的简单函数,例如,计算指定范围内的数字的和或阶乘.后来,我们发现它在处理递归数据结构,最重要的列表是时,是无价的. 我们知道,递归也有一些局限性,堆栈溢出的可能性是最明显的一个:我们将会看到,某些递归计算非常低效.在命令式语言中,通常使用非递归函数,以避免出现问题:函数语言已经有方法解决这些问题,并可以高效地使用递归.首先要集中关注于正确性:如果一个额外的字节吹动堆栈,真正