mysql计算指定的时间TPS

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:
<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    


 

版权声明:本文博主原创文章。博客,未经同意不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4890003.html,如需转载请自行联系原作者


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5月前
|
存储 关系型数据库 MySQL
MYSQL 单表可以放多少数据是怎么计算出来的
MYSQL 单表可以放多少数据是怎么计算出来的
114 1
|
5月前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL版标准版计算节点规格详解
PolarDB MySQL版标准版计算节点规格详解
155 1
|
3月前
|
关系型数据库 MySQL 数据库
MySQL 保姆级教程(八):创建计算字段
MySQL 保姆级教程(八):创建计算字段
|
4月前
|
分布式计算 大数据 关系型数据库
MaxCompute产品使用问题之mysql读取从mc里的每10分钟计算好的结果数据表,如何同步数据过去
MaxCompute作为一款全面的大数据处理平台,广泛应用于各类大数据分析、数据挖掘、BI及机器学习场景。掌握其核心功能、熟练操作流程、遵循最佳实践,可以帮助用户高效、安全地管理和利用海量数据。以下是一个关于MaxCompute产品使用的合集,涵盖了其核心功能、应用场景、操作流程以及最佳实践等内容。
|
4月前
|
存储 SQL 关系型数据库
MySQL快速回顾:计算字段与函数
MySQL快速回顾:计算字段与函数
|
4月前
|
关系型数据库 MySQL Serverless
【随手记】MySQL窗口函数计算累加和
【随手记】MySQL窗口函数计算累加和
280 0
|
5月前
|
缓存 监控 关系型数据库
2核4G 配置的MySQL 5.6如何调优为最佳qps,tps
要提高具有2核4G配置的MySQL 5.6的QPS(每秒查询率)和TPS(每秒事务数),可以通过以下方法进行调优: 1. 优化配置文件(my.cnf): 在MySQL的配置文件中,可以调整以下参数以提高性能: ``` [mysqld] innodb_buffer_pool_size = 1.5G # 设置InnoDB缓冲池大小,推荐值为服务器总内存的50%-80% max_connections = 500 # 设置最大连接数,根据实际需求进行调整 query_cache_size = 128M # 设置查询缓存大小,推荐值
411 2
|
5月前
|
关系型数据库 MySQL Unix
MySQL 计算时间差分钟
【5月更文挑战第3天】
|
4月前
|
关系型数据库 MySQL
Mysql 中位数计算
Mysql 中位数计算
31 0
|
5月前
|
关系型数据库 MySQL
Mysql基础第十三天,创建计算字段
Mysql基础第十三天,创建计算字段
30 0
下一篇
无影云桌面