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='\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的username
MYSQL_PASS='123' #mysql的登录用户password
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${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 "正在获取TPS值:" 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}'}'` #shell默认不支持浮点运算 cechon "Within the last $sleep_time seconds,TPS is: ${tps_avg} " red
echo " "
echo " "
rm -rf ${tps_re021}
rm -rf ${tps_re022}
rm -rf ${tps_re023} ############执行结果
正在获取TPS值:
Within the last 10 seconds,TPS is: 0.9
版权声明:本文博主原创文章。博客,未经同意不得转载。
mysql计算指定的时间TPS的更多相关文章
- MySql计算两日期时间之间相差的天数,秒数,分钟数,周数,小时数
MySql计算两日期时间之间相差的天数,秒数,分钟数,周数,小时数 计算两日期时间之间相差的天数,秒数,分钟数,周数,小时数,这里主要分享的是通过MySql内置的函数 TimeStampDiff() ...
- MySQL --- 计算指定日期为当月的第几周
SET @d=NOW(); ; 啦啦啦
- mysql 计算两个时间之间有多少分钟
SELECT TIMESTAMPDIFF(MINUTE, (DATE_FORMAT('2015-08-12 10:38:00','%Y-%m-%d %H:%i')), (DATE_FORMAT('20 ...
- NET MVC全局异常处理(一) 【转载】网站遭遇DDoS攻击怎么办 使用 HttpRequester 更方便的发起 HTTP 请求 C#文件流。 Url的Base64编码以及解码 C#计算字符串长度,汉字算两个字符 2019周笔记(2.18-2.23) Mysql语句中当前时间不能直接使用C#中的Date.Now传输 Mysql中Count函数的正确使用
NET MVC全局异常处理(一) 目录 .NET MVC全局异常处理 IIS配置 静态错误页配置 .NET错误页配置 程序设置 全局异常配置 .NET MVC全局异常处理 一直知道有.NET有相关 ...
- iOS规范化时间格式,object-C计算指定时间与当前的时间差
object-c计算指定时间与当前的时间差 头文件(.h): #import <Foundation/Foundation.h> @interface LuDate : NSDate +( ...
- [php基础]Mysql日期函数:日期时间格式转换函数详解
在PHP网站开发中,Mysql数据库设计中日期时间字段必不可少,由于Mysql日期函数输出的日期格式与PHP日期函数之间的日期格式兼容性不够,这就需要根据网站实际情况使用Mysql或PHP日期转换函数 ...
- MySQL计算日期的函数DATE_SUB(d,INTERVAL expr type)
MySQL计算日期的函数DATE_SUB(d,INTERVAL expr type) DATE_SUB(d,INTERVAL expr type)函数返回起始日期d减去一个时间段后的日期. expr是 ...
- mysql常处理用时间sql语句
Mysql日期函数,时间函数使用的总结,以及时间加减运算(转) select timediff('23:40:00', ' 18:30:00'); -- 两时间相减SELECT substring( ...
- mysql计算时间差函数
MySql计算两个日期的时间差函数TIMESTAMPDIFF用法,只要用一句SQL语句就可以办到了. MySql计算两个日期的时间差函数TIMESTAMPDIFF用法: 语法: TIMESTAMPDI ...
随机推荐
- php编码
原文:php编码 PHP 页面编码声明与用header或meta实现PHP页面编码的区别 php的header来定义一个php页面为utf编码或GBK编码 php页面为utf编码 header ...
- MySQL触发器 trigger之for each row
for each row 每行受影响,触发器都运行.叫行级触发器. oracle 触发器中分行级触发器和语句级触发器,可不写for each row,不管影响多少行都仅仅运行一次. mysql不支持语 ...
- 【PostgreSQL】PostgreSQL语法
在阅读的过程中有不论什么问题.欢迎一起交流 邮箱:1494713801@qq.com QQ:1494713801 一.PostgreSQL时间类型转换 --时间类型转成字符类型 select t ...
- OCP读书笔记(13) - 管理内存
SGA 1. 什么是LRULRU表示Least Recently Used,也就是指最近最少使用的buffer header链表LRU链表串联起来的buffer header都指向可用数据块 2. 什 ...
- loj1201(最大独立集)
传送门:A Perfect Murder 题意:有一群苍蝇,之间有一些是朋友关系,如果杀了一只苍蝇,那么它的朋友们都会有警惕性,再也杀不了这些朋友了,问最多能杀多少只苍蝇. 分析:根据朋友性连边,最多 ...
- sqlit使用要点之引入libsqlite3.dylib
怎样引入libsqlite3.dylib? 在.h 或 .cpp文件里包括相应的头文件
- setChecked方法触发onCheckedChanged监听器问题
有时须要在程序初始化界面时,讲有些比如toggleButton等控件依照需求勾选,此时会发现,当我setChecked时会触发onCheckedChanged监听器,导致这部分代码被调用两次.解决方法 ...
- hdu2569(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2569 分析: f(n),n个珠子的合格数:a(n),n个珠子,最后2个相同的合格数:b(n),n个珠子 ...
- hdu 4739【位运算】.cpp
题意: 给出n个地雷所在位置,正好能够组成正方形的地雷就可以拿走..为了简化题目,只考虑平行于横轴的正方形.. 问最多可以拿走多少个正方形.. 思路: 先找出可以组成正方形的地雷组合cnt个.. 然后 ...
- 【剑指offer】面试题24:二叉搜索树的兴许前序遍历序列
分析: 前序: 根 左 右 后序: 左 由 根 二叉搜索树: 左 < 根 < 右 那么这就非常明显了. def ifpost(postArray, start, end): #one or ...